package com.example.makerspace.manager;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.makerspace.config.SendMessageConfig;
import com.example.makerspace.dao.*;
import com.example.makerspace.domain.*;
import com.example.makerspace.dto.*;
import com.example.makerspace.enums.QuestionsEnum;
import com.example.makerspace.enums.ResultCodeEnum;
import com.example.makerspace.enums.SubmissionCodeEnum;
import com.example.makerspace.model.ApplicationStatus;
import com.example.makerspace.model.FailMsg;
import com.example.makerspace.utils.*;
import com.example.makerspace.vo.*;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.util.ObjectUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

import static com.example.makerspace.enums.ApplicationStatusEnum.*;
import static com.example.makerspace.manager.DataManager.*;
import static com.example.makerspace.service.impl.AdminServiceImpl.managerMap;
import static com.example.makerspace.utils.DateUtils.YYYY_MM_DD;


@Component
public class ApplicationV2Manager extends BaseManager<ApplicationV2DO, ApplicationV2DTO> {
    private final static String DEMAND_PICTURE_PATH_PREFIX = "demand/";
    private final static String RESOURCE_PATH_PREFIX = "resource/";

    private  final  static  String  productType="上架产品";

    private  final  static  String EntType="企业认证";

    private  final  static  Integer EntPoint=10;

    private  final  static  Integer  productPoint=10;

  private  final  static  String   testHttpPrefix="https://119.45.199.13:3035/static/";


   private  final  static  String  devHttpPrefix="https://nism.ytcata.com:443/static/";

    @Resource
    private  CustomerNumberDAO customerNumberDAO;


    @Resource
    private  CompetitionParentDAO competitionParentDAO;

    @Resource
    private ApplicationV2DAO applicationV2DAO;


    @Resource
    private  DemandRecordDAO demandRecordDAO;

    @Resource
    private  NewsDAO newsDAO;

    @Resource
    private EntRelationsDAO entRelationsDAO;

    @Resource
    private  UsersOnlineDAO usersOnlineDAO;

    @Resource
    private  WebViewDAO webViewDAO;


    @Resource
    private  RedisUtils redisUtils;

    @Resource
    private  BmsLogServiceDAO bmsLogServiceDAO;



    @Resource
    private  ExpertInfoDAO expertInfoDAO;




    @Resource
    private  SingInRecordDAO singInRecordDAO;


    @Resource
    private  UserFormsDAO userFormsDAO;


    @Resource
    private  SmsErrLogDAO smsErrLogDAO;


    @Resource
    private TaskFinishDAO taskFinishDAO;

    @Resource
    private  StageFormDAO stageFormDAO;


    @Resource
    private  DeleteDemandDAO  deleteDemandDAO;


    @Resource
    private  AgencyProductRelationshipsDAO agencyProductRelationshipsDAO;





    @Resource
    private CompetitionManager competitionManager;


    @Resource
    private CompetitionDAO competitionDAO;

    @Resource
    private TaskTagDAO taskTagDAO;


    @Resource
    private  ExpertOutcomeDAO expertOutcomeDAO;







    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Resource
    private UserDAO userDAO;

    @Resource
    private DemandDAO demandDAO;



    @Resource
    private CompetitionSubmissionDAO competitionSubmissionDAO;

    @Resource
    private ArtworkReviewDAO artworkReviewDAO;

    @Resource
    private RecommendDAO recommendDAO;

    @Resource
    private  PointBreakdownDAO  pointBreakdownDAO;

    @Resource
    private  StagingProductDAO stagingProductDAO;

    @Resource
    private UserCompetitionRelationShipDAO userCompetitionRelationShipDAO;


    @Resource
    private  PersonalRecommendationsDAO personalRecommendationsDAO;


    @Resource
    private UserAuthenticationDAO userAuthenticationDAO;


    @Resource
    private EnterpriseCertificationDAO enterpriseCertificationDAO;


    @Resource
    private CompetitionChangeRecordDAO competitionChangeRecordDAO;


     @Resource
     private  EnterpriseDataDAO enterpriseDataDAO;


    @Resource
    private SendMessageConfig sendMessageConfig;



    @Resource
    private MessageDAO messageDAO;

    @Resource
    private  ArtificialntelligenceDAO artificialntelligenceDAO;


    @Resource
    private  ProductBulletinsDAO productBulletinsDAO;

    @Resource
    private  DemandLookDAO demandLookDAO;




    @Resource
    private  MeetingDAO meetingDAO;

    @PostConstruct
    public void init() {
        this.baseDAO = applicationV2DAO;
        managerMap.put("applicationV2", this);
    }

    private final static String ATTACHMENT_PATH_PREFIX = "attachment/";
    private final static List<Map<String, String>> FUZZY_QUERY_PARAMS = Lists.newArrayList(
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "username").put(QUERY_TYPE, QUERY_TYPE_TERM).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "contact").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "phone").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "biz_type").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "biz_overview").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "region").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "phone").put(QUERY_TYPE, QUERY_TYPE_TERM).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "adv_intro").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "ip_type").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "patent_type").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "granted_patents").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "pending_patents").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "software_status").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "publications").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "team_members").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build(),
            ImmutableMap.<String, String>builder().put(QUERY_FIELD, "status").put(QUERY_TYPE, QUERY_TYPE_MATCH_PHRASE).build()
    );

    public final static Map<String, String> APPLICATION_STATUS_MAP = ImmutableMap.<String, String>builder()
            .put(REVIEWING.getCode(), REVIEWING.getDesc())
            .put(APPLICATION_SUCCESS.getCode(), APPLICATION_SUCCESS.getDesc())
            .put(APPLICATION_FAIL.getCode(), APPLICATION_FAIL.getDesc())
            .build();

    public final static Set<String> FAIL_STATUS = ImmutableSet.<String>builder()
            .add("-1")
            .add("-2")
            .add("-3")
            .add("-4")
            .build();

    public final static Set<String> SUCCESS_STATUS = ImmutableSet.<String>builder()
            .add("1")
            .add("2")
            .add("3")
            .add("4")
            .build();

    public Result addApplicationV2(ApplicationV2DTO applicationV2DTO) {
        String username = applicationV2DTO.getUsername();
        Integer competitionId = applicationV2DTO.getCompetitionId();
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectIsApplication(username, competitionId);
        if (CollectionUtils.isNotEmpty(applicationV2DOList)) {
            return Result.error(ResultCodeEnum.ALREADY_APPLICATION);
        }
        if (applicationV2DTO.getUsername().equals("") || applicationV2DTO.getCompetitionParentId() == 0) {
            return Result.error(ResultCodeEnum.MUST_NOT_EXIST);
        }
        ApplicationV2DO applicationV2DO = new ApplicationV2DO();

        if (!ObjectUtils.isEmpty(applicationV2DTO.getAttachments())) {
            String path = FileUtils.saveMultipartFile(applicationV2DTO.getAttachments(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + applicationV2DTO.getUsername());
            applicationV2DO.setAttachments(path);
        }
        applicationV2DO.setUsername(applicationV2DTO.getUsername());
        applicationV2DO.setCompetitionParentId(applicationV2DTO.getCompetitionParentId());
        BeanUtils.copyProperties(applicationV2DTO, applicationV2DO);
        applicationV2DO.setStatus(REVIEWING.getDesc());
        CompetitionDO competitionDO = competitionDAO.selectByCompetitionId(applicationV2DO.getCompetitionId());
        applicationV2DO.setCompetitionName(competitionDO.getTitle());
        applicationV2DAO.insert(applicationV2DO);
        UserCompetitionRelationShipDO userCompetitionRelationShipDO = new UserCompetitionRelationShipDO();
        userCompetitionRelationShipDO.setUsername(applicationV2DTO.getUsername());
        userCompetitionRelationShipDO.setCompetitionId(applicationV2DTO.getCompetitionId());
        userCompetitionRelationShipDO.setState(QuestionsEnum.REVIEWING.getDesc());
        userCompetitionRelationShipDAO.insert(userCompetitionRelationShipDO);
        MessageDO messageDO = new MessageDO();
        messageDO.setType(1);
        messageDO.setTitle("赛题报名消息");
        messageDO.setContent("您好!您的的" + applicationV2DTO.getBizName() + "赛题报名成功!");
        messageDO.setUsername(username);
        try {
            MessageUtils.sendMessage(username, sendMessageConfig.getQuestionApplication());
        }catch (Exception e){
            SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
            smsErrLogDO.setPhone(username);
            smsErrLogDO.setType("赛题报名成功");
            smsErrLogDAO.insert(smsErrLogDO);
        }
        return Result.success(ResultCodeEnum.Enroll_Querstion_SUCEESS);
    }

    public void addApplication(ApplicationV2DTO applicationDTO) {
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"));
        calendar.setTime(new Date());
        String dayApplicationKey = String.format(DAY_APPLICATION, calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR));
        Long dayApplication = Long.parseLong((String) Optional.ofNullable(redisTemplate.opsForValue().get(dayApplicationKey)).orElse("0")) + 1L;
        Long applicationCount = Long.parseLong((String) Optional.ofNullable(redisTemplate.opsForValue().get(APPLICATION_COUNT)).orElse("0")) + 1L;
        HashMap<String, String> regionMap = (HashMap<String, String>) Optional.ofNullable(redisTemplate.opsForValue().get(REGION)).orElse(Maps.newHashMap());
        HashMap<String, String> projectTypeMap = (HashMap<String, String>) Optional.ofNullable(redisTemplate.opsForValue().get(PROJECT_TYPE)).orElse(Maps.newHashMap());
        String region = applicationDTO.getRegion();
        Long count1 = Long.parseLong(regionMap.getOrDefault(region, "0")) + 1L;
        regionMap.put(region, String.valueOf(count1));

        redisTemplate.opsForValue().set(dayApplicationKey, String.valueOf(dayApplication));
        redisTemplate.opsForValue().set(APPLICATION_COUNT, String.valueOf(applicationCount));
        redisTemplate.opsForValue().set(REGION, regionMap);
    }

    public Result checkApplication(HttpServletRequest request, Integer competitionParentId) {
        String username = JwtUtils.getUsername(request);
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectIsEnroll(username, competitionParentId);
        if (CollectionUtils.isEmpty(applicationV2DOList)) {
            return Result.success("该用户未收集信息");
        }
        ApplicationV2DO applicationV2DO = applicationV2DOList.get(0);
        ApplicationV2DTO applicationV2DTO = convert2DTO(applicationV2DO);
        return Result.success(ResultCodeEnum.ALREADY_APPLICATION, applicationV2DTO);
    }

    public static String titleSecrecy(String phoneNum) {
        if (phoneNum.length() > 8) {
            phoneNum = phoneNum.substring(0, 3) + "****" + phoneNum.substring(7, phoneNum.length());
        } else {
            phoneNum = phoneNum.substring(0, 3) + "****";
        }
        return phoneNum;
    }

    public Result checkCompetition(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        IPage<CompetitionDO> competitionDOIPage = competitionDAO.selectByCompetitionParentId(pagination.getPageNum(), pagination.getSize(), pageRequest.getCompetitionParentId());
        List<CompetitionDO> records = competitionDOIPage.getRecords();
        Map<String, Object> params = pageRequest.getParams();
        String username = MapUtils.getString(params, "username");
        UserDO userDO = userDAO.selectByUsername(username);
        List<CompetitionBriefInformationDTO> competitionBriefInformationDTOList = new ArrayList<>(records.size());
        List<CompetitionDO> competitionDOList = new ArrayList<>(records.size());
        for (int i = 0; i < records.size(); i++) {
            if (records.get(i).getIsPublic() == 1) {
                CompetitionBriefInformationDTO competitionBriefInformationDTO = new CompetitionBriefInformationDTO();
                CompetitionDO competitionDO = new CompetitionDO();
                competitionBriefInformationDTO.setContent(records.get(i).getContent());
                competitionBriefInformationDTO.setIsPublic(records.get(i).getIsPublic());
                competitionBriefInformationDTO.setTitle(records.get(i).getTitle());
                competitionBriefInformationDTO.setId(records.get(i).getId());
                competitionBriefInformationDTO.setSortId(records.get(i).getSortId());
                BeanUtils.copyProperties(competitionBriefInformationDTO, competitionDO);
                competitionBriefInformationDTOList.add(competitionBriefInformationDTO);
                competitionDOList.add(competitionDO);
            } else {
                CompetitionBriefInformationDTO competitionBriefInformationDTO = new CompetitionBriefInformationDTO();
                CompetitionDO competitionDO = new CompetitionDO();
                if (userDO.getIsAuthentication() == 1) {
                    competitionBriefInformationDTO.setTitle((records.get(i).getTitle()));
                } else {
                    competitionBriefInformationDTO.setTitle(titleSecrecy(records.get(i).getTitle()));
                }
                competitionBriefInformationDTO.setContent(records.get(i).getContent());
                competitionBriefInformationDTO.setIsPublic(records.get(i).getIsPublic());
                competitionBriefInformationDTO.setId(records.get(i).getId());
                competitionBriefInformationDTO.setSortId(records.get(i).getSortId());
                BeanUtils.copyProperties(competitionBriefInformationDTO, competitionDO);
                competitionBriefInformationDTOList.add(competitionBriefInformationDTO);
                competitionDOList.add(competitionDO);
            }
        }
        competitionDOIPage.setRecords(competitionDOList);
        return Result.success(competitionDOIPage);
    }

    public Result selectCompetition(HttpServletRequest request, Integer competitionId, Integer competitionParentId) {
        String username = JwtUtils.getUsername(request);
        UserDO userDO = userDAO.selectByUsername(username);
        CompetitionDO competitionDO = competitionDAO.selectByIdAndCompetitionParentId(competitionId, competitionParentId);
        CompetitionDO aboutCompetitionDO = new CompetitionDO();
        aboutCompetitionDO.setTitle(competitionDO.getTitle());
        aboutCompetitionDO.setContent(competitionDO.getContent());
        aboutCompetitionDO.setQualityStandards(competitionDO.getQualityStandards());
        aboutCompetitionDO.setOutcomeFormat(competitionDO.getOutcomeFormat());
        List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByCompetitionId(username, competitionId);
        if (competitionDO.getIsPublic() == 0) {
            //如果没有完成登入先登录
            if (userDO == null) {
                return Result.error(ResultCodeEnum.UNSIGNED_USER);
            }
            Integer isAuthentication = userDO.getIsAuthentication();
            //如果没有认证就去完成认证
            if (isAuthentication == 0) {
                return Result.error(ResultCodeEnum.Unable_Finally_Authentication);
            }
            if (userDO != null && isAuthentication == 1) {
                if (!CollectionUtils.isEmpty(userCompetitionRelationShipDOS)) {
                    UserCompetitionRelationShipDO userCompetitionRelationShipDO = userCompetitionRelationShipDOS.get(0);
                    if (userCompetitionRelationShipDO.getState().equals("成功")) {
                        return Result.success(competitionDO);
                    }
                } else {
                    return Result.success(aboutCompetitionDO);
                }
            }
        }else {
           return  Result.success(competitionDO);
            }
        return Result.success(competitionDO);
    }

    @Override
    public ApplicationV2DTO convert2DTO(ApplicationV2DO applicationV2DO) {
        ApplicationV2DTO applicationV2DTO = super.convert2DTO(applicationV2DO);
        String status = APPLICATION_STATUS_MAP.get(applicationV2DO.getStatus());
        applicationV2DTO.setStatus(status);
        applicationV2DTO.setFail(FAIL_STATUS.contains(applicationV2DO.getStatus()));
        Optional.ofNullable(applicationV2DO.getCompetitionId()).ifPresent(competition -> {
            applicationV2DTO.setCompetitionDTO(competitionManager.detailByID(competition));
        });
        return applicationV2DTO;
    }

    @Override
    public Result deleteById(int id) {
        ApplicationV2DO applicationV2DO = applicationV2DAO.selectById(id);

        return super.deleteById(id);
    }


    @Override
    public Result update(Map<String, Object> params) {
        ApplicationV2DTO applicationV2DTO = null;
        try {
            applicationV2DTO = MakerSpaceMapUtils.mapToObj(params, ApplicationV2DTO.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        Integer id = applicationV2DTO.getId();
        ApplicationV2DO applicationV2DO = applicationV2DAO.selectById(id);
        if (applicationV2DO == null) {
            return Result.error(ResultCodeEnum.APPLICATION_NOT_EXIST);
        }
        Optional.ofNullable(applicationV2DTO.getUsername()).ifPresent(applicationV2DO::setUsername);
        Optional.ofNullable(applicationV2DTO.getBizName()).ifPresent(applicationV2DO::setBizName);
        Optional.ofNullable(applicationV2DTO.getContact()).ifPresent(applicationV2DO::setContact);
        Optional.ofNullable(applicationV2DTO.getPhone()).ifPresent(applicationV2DO::setPhone);
        Optional.ofNullable(applicationV2DTO.getBizType()).ifPresent(applicationV2DO::setBizType);
        Optional.ofNullable(applicationV2DTO.getBizOverview()).ifPresent(applicationV2DO::setBizOverview);
        Optional.ofNullable(applicationV2DTO.getRegion()).ifPresent(applicationV2DO::setRegion);
        Optional.ofNullable(applicationV2DTO.getAdvIntro()).ifPresent(applicationV2DO::setAdvIntro);
        Optional.ofNullable(applicationV2DTO.getHaveIp()).ifPresent(applicationV2DO::setHaveIp);
        Optional.ofNullable(applicationV2DTO.getIpType()).ifPresent(applicationV2DO::setIpType);
        Optional.ofNullable(applicationV2DTO.getPatentType()).ifPresent(applicationV2DO::setPatentType);
        Optional.ofNullable(applicationV2DTO.getGrantedPatents()).ifPresent(applicationV2DO::setGrantedPatents);
        Optional.ofNullable(applicationV2DTO.getPendingPatents()).ifPresent(applicationV2DO::setPendingPatents);
        Optional.ofNullable(applicationV2DTO.getSoftwareStatus()).ifPresent(applicationV2DO::setSoftwareStatus);
        Optional.ofNullable(applicationV2DTO.getPublications()).ifPresent(applicationV2DO::setPublications);
        Optional.ofNullable(applicationV2DTO.getTeamMembers()).ifPresent(applicationV2DO::setTeamMembers);
        Optional.ofNullable(applicationV2DTO.getCompetitionId()).ifPresent(applicationV2DO::setCompetitionId);
        Optional.ofNullable(applicationV2DTO.getReviewFeedback()).ifPresent(applicationV2DO::setReviewFeedback);
        String msg = applicationV2DTO.getMsg();
        Optional.ofNullable(applicationV2DTO.getStatus()).ifPresent(status -> {
            List<ApplicationStatus> statusLine = applicationV2DO.getStatusLine();
            if (CollectionUtils.isEmpty(statusLine)) {
                statusLine = Lists.newLinkedList();
            }
            List<String> statusList = statusLine.stream().map(ApplicationStatus::getStatusCode).distinct().collect(Collectors.toList());
//            if(CollectionUtils.isNotEmpty(statusLine)){
//                ApplicationStatus applicationStatus = statusLine.get(statusLine.size() - 1);
//                if(FAIL_STATUS.contains(applicationStatus.getStatusCode())){
//                    statusLine.remove(statusLine.size() - 1);
//                }
//            }
            if (!statusList.contains(status)) {
                ApplicationStatus applicationStatus = new ApplicationStatus();
                applicationStatus.setStatus(APPLICATION_STATUS_MAP.get(status));
                applicationStatus.setStatusCode(status);
                applicationStatus.setTime(DateUtils.format(new Date(System.currentTimeMillis()), YYYY_MM_DD));
                statusLine.add(applicationStatus);
                applicationV2DO.setStatusLine(statusLine);
                if (FAIL_STATUS.contains(status)) {
                    List<FailMsg> failHistory = Optional.ofNullable(applicationV2DO.getFailHistory()).orElse(Lists.newArrayList());
                    FailMsg failMsg = new FailMsg();
                    if (StringUtils.isNotBlank(msg)) {
                        failMsg.setMessage(msg);
                    }
                    failMsg.setStatus(APPLICATION_STATUS_MAP.get(status));
                    failMsg.setStatusCode(status);
                    failMsg.setTime(DateUtils.format(new Date(System.currentTimeMillis()), YYYY_MM_DD));
                    failHistory.add(failMsg);
                    applicationV2DO.setFailHistory(failHistory);
                }
            }
            applicationV2DO.setStatus(status);
        });
        Optional.ofNullable(applicationV2DTO.getMsg()).ifPresent(applicationV2DO::setMsg);
        return updateDO(applicationV2DO);
    }


    @Override
    public PageResult list(PageRequest pageRequest) {
        Map<String, Object> params = pageRequest.getParams();
        Pagination pagination = pageRequest.getPagination();
        String fuzzy = MapUtils.getString(params, "fuzzy");
        if (StringUtils.isBlank(fuzzy)) {
            return super.list(pageRequest);
        }
        return search(null, null, FUZZY_QUERY_PARAMS, fuzzy, pagination, ApplicationV2DO.class);
    }


    public Result save(ApplicationV2DTO applicationV2DTO) {
        Integer id = applicationV2DTO.getId();
        ApplicationV2DO applicationV2DO = applicationV2DAO.selectById(id);
        if (applicationV2DO == null) {
            return Result.error(ResultCodeEnum.APPLICATION_NOT_EXIST);
        }
//        if (!FAIL_STATUS.contains(applicationV2DO.getStatus())) {
//            return Result.error(ResultCodeEnum.NOT_ALLOWED_STATUS);
//        }
        Optional.ofNullable(applicationV2DTO.getBizName()).ifPresent(applicationV2DO::setBizName);
        Optional.ofNullable(applicationV2DTO.getContact()).ifPresent(applicationV2DO::setContact);
        Optional.ofNullable(applicationV2DTO.getPhone()).ifPresent(applicationV2DO::setPhone);
        Optional.ofNullable(applicationV2DTO.getBizType()).ifPresent(applicationV2DO::setBizType);
        Optional.ofNullable(applicationV2DTO.getBizOverview()).ifPresent(applicationV2DO::setBizOverview);
        Optional.ofNullable(applicationV2DTO.getRegion()).ifPresent(applicationV2DO::setRegion);
        Optional.ofNullable(applicationV2DTO.getAdvIntro()).ifPresent(applicationV2DO::setAdvIntro);
        Optional.ofNullable(applicationV2DTO.getHaveIp()).ifPresent(applicationV2DO::setHaveIp);
        Optional.ofNullable(applicationV2DTO.getIpType()).ifPresent(applicationV2DO::setIpType);
        Optional.ofNullable(applicationV2DTO.getPatentType()).ifPresent(applicationV2DO::setPatentType);
        Optional.ofNullable(applicationV2DTO.getGrantedPatents()).ifPresent(applicationV2DO::setGrantedPatents);
        Optional.ofNullable(applicationV2DTO.getPendingPatents()).ifPresent(applicationV2DO::setPendingPatents);
        Optional.ofNullable(applicationV2DTO.getSoftwareStatus()).ifPresent(applicationV2DO::setSoftwareStatus);
        Optional.ofNullable(applicationV2DTO.getPublications()).ifPresent(applicationV2DO::setPublications);
        Optional.ofNullable(applicationV2DTO.getTeamMembers()).ifPresent(applicationV2DO::setTeamMembers);
        Optional.ofNullable(applicationV2DTO.getCompetitionId()).ifPresent(applicationV2DO::setCompetitionId);
        Optional.ofNullable(applicationV2DTO.getCompetitionParentId()).ifPresent(applicationV2DO::setCompetitionParentId);
        if (!ObjectUtils.isEmpty(applicationV2DTO.getAttachments())) {
            String path = FileUtils.saveMultipartFile(applicationV2DTO.getAttachments(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + applicationV2DTO.getUsername());
            applicationV2DO.setAttachments(path);
        }
        List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByCompetitionId(applicationV2DTO.getUsername(), applicationV2DTO.getCompetitionId());
        if (!CollectionUtils.isEmpty(userCompetitionRelationShipDOS)) {
            UserCompetitionRelationShipDO userCompetitionRelationShipDO = userCompetitionRelationShipDOS.get(0);
            userCompetitionRelationShipDO.setState("0");
            userCompetitionRelationShipDAO.updateById(userCompetitionRelationShipDO);
        }
        return updateDO(applicationV2DO);
    }

    public Result submit(ApplicationV2DTO applicationV2DTO) {
        Integer id = applicationV2DTO.getId();
        ApplicationV2DO applicationV2DO = applicationV2DAO.selectById(id);
        if (applicationV2DO == null) {
            return Result.error(ResultCodeEnum.APPLICATION_NOT_EXIST);
        }
        if (applicationV2DO.getStatus().equals("0")) {
            return Result.error(ResultCodeEnum.NOT_ALLOWED_STATUS);
        }
        applicationV2DO.setStatusLine(Lists.newLinkedList());
        applicationV2DO.setStatus(REVIEWING.getCode());
        applicationV2DO.setMsg("");
        return updateDO(applicationV2DO);
    }

    public void deleteByUser(UserDO userDO) {
        ApplicationV2DO applicationV2DO = applicationV2DAO.selectByUsername(userDO.getUsername());
        if (applicationV2DO == null) {
            return;
        }
        applicationV2DAO.deleteById(applicationV2DO.getId());
    }

    public Result addRegistration(ApplicationV2DTO applicationV2DTO) {
        String path = FileUtils.saveMultipartFile(applicationV2DTO.getAttachments(),
                FileUtils.staticPath + RESOURCE_PATH_PREFIX + applicationV2DTO.getUsername());
        ApplicationV2DO applicationV2DO = new ApplicationV2DO();
        applicationV2DO.setAttachments(path);
        applicationV2DO.setStatus(REVIEWING.getCode());
        BeanUtils.copyProperties(applicationV2DTO, applicationV2DO);
        applicationV2DO.setStatus("0");
        applicationV2DAO.insert(applicationV2DO);
        return Result.success("添加成功");
    }

    public Result updateApplication(ApplicationV2DTO applicationV2DTO) {
        Integer id = applicationV2DTO.getId();
        ApplicationV2DO applicationV2DO = applicationV2DAO.selectById(id);
        List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByCompetitionId(applicationV2DO.getUsername(), applicationV2DTO.getCompetitionId());
        if(CollectionUtils.isEmpty(userCompetitionRelationShipDOS)){
            userCompetitionRelationShipDOS.get(0).setReviewFeedback(applicationV2DTO.getReviewFeedback());
        }
        if (applicationV2DO == null) {
            return Result.error(ResultCodeEnum.APPLICATION_NOT_EXIST);
        }
        Optional.ofNullable(applicationV2DTO.getBizName()).ifPresent(applicationV2DO::setBizName);
        Optional.ofNullable(applicationV2DTO.getStatus()).ifPresent(applicationV2DO::setStatus);
        Optional.ofNullable(applicationV2DTO.getContact()).ifPresent(applicationV2DO::setContact);
        Optional.ofNullable(applicationV2DTO.getPhone()).ifPresent(applicationV2DO::setPhone);
        Optional.ofNullable(applicationV2DTO.getBizType()).ifPresent(applicationV2DO::setBizType);
        Optional.ofNullable(applicationV2DTO.getBizOverview()).ifPresent(applicationV2DO::setBizOverview);
        Optional.ofNullable(applicationV2DTO.getRegion()).ifPresent(applicationV2DO::setRegion);
        Optional.ofNullable(applicationV2DTO.getAdvIntro()).ifPresent(applicationV2DO::setAdvIntro);
        Optional.ofNullable(applicationV2DTO.getHaveIp()).ifPresent(applicationV2DO::setHaveIp);
        Optional.ofNullable(applicationV2DTO.getIpType()).ifPresent(applicationV2DO::setIpType);
        Optional.ofNullable(applicationV2DTO.getPatentType()).ifPresent(applicationV2DO::setPatentType);
        Optional.ofNullable(applicationV2DTO.getGrantedPatents()).ifPresent(applicationV2DO::setGrantedPatents);
        Optional.ofNullable(applicationV2DTO.getPendingPatents()).ifPresent(applicationV2DO::setPendingPatents);
        Optional.ofNullable(applicationV2DTO.getSoftwareStatus()).ifPresent(applicationV2DO::setSoftwareStatus);
        Optional.ofNullable(applicationV2DTO.getPublications()).ifPresent(applicationV2DO::setPublications);
        Optional.ofNullable(applicationV2DTO.getTeamMembers()).ifPresent(applicationV2DO::setTeamMembers);
        Optional.ofNullable(applicationV2DTO.getCompetitionId()).ifPresent(applicationV2DO::setCompetitionId);
        Optional.ofNullable(applicationV2DTO.getCompetitionParentId()).ifPresent(applicationV2DO::setCompetitionParentId);
        Optional.ofNullable(applicationV2DTO.getReviewFeedback()).ifPresent(applicationV2DO::setReviewFeedback);
        MultipartFile attachments = applicationV2DTO.getAttachments();
        if (attachments != null) {
            String path = FileUtils.saveMultipartFile(applicationV2DTO.getAttachments(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + applicationV2DTO.getUsername());
            applicationV2DO.setAttachments(path);
        }
        return updateDO(applicationV2DO);

    }

    public Result deleteApplication(Integer id, String username, Integer competitionId) {
        deleteById(id);
        userCompetitionRelationShipDAO.deleteByUsernameAndCompetitionId(username, competitionId);
        artworkReviewDAO.deleteByUsernameAndCompetitionId(username, id);
        competitionSubmissionDAO.deleteByUsernameAndCompetitionId(username, id);
        recommendDAO.deleteByUsernameAndCompetitionId(username, id);
        return Result.success("删除成功");
    }

    public Result processStatus(HttpServletRequest request, Integer competitionParentId) {
        //ProcessStatusVO processStatusVO = new ProcessStatusVO();
        String competitionState = "";
        String submissionState = "";
        String username = JwtUtils.getUsername(request);
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectIsEnroll(username, competitionParentId);
        if (CollectionUtils.isEmpty(applicationV2DOList)) {
            return Result.success(ResultCodeEnum.USER_NO_Application);
        }
        ApplicationV2DO applicationV2DO = applicationV2DOList.get(0);
        List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByUsername(username);
        List<CompetitionSubmissionDO> competitionSubmissionDOS = competitionSubmissionDAO.selectByUsername(username);
        if (!CollectionUtils.isEmpty(userCompetitionRelationShipDOS)) {
            competitionState = handleCompetitionState(userCompetitionRelationShipDOS, competitionState);
        }
        if (!CollectionUtils.isEmpty(competitionSubmissionDOS)) {
            submissionState = handleSubmissionState(competitionSubmissionDOS, submissionState);
        }
        if (!submissionState.equals("")) {

            return Result.success(ResultCodeEnum.Submission, submissionState);
        } else if (submissionState.equals("") && !competitionState.equals("")) {
            return Result.success(ResultCodeEnum.Question_Selection, competitionState);
        } else if (competitionState.equals("") && !applicationV2DO.getStatus().equals("")) {
            return Result.success(ResultCodeEnum.Register_Competition, applicationV2DO.getStatus());
        }
        return Result.success();
    }

    private static String handleSubmissionState(List<CompetitionSubmissionDO> competitionSubmissionDOS, String submissionState) {
        for (CompetitionSubmissionDO competitionSubmissionDO : competitionSubmissionDOS) {
            if (competitionSubmissionDO.getState().equals(SubmissionCodeEnum.SUBMISSION_FAIL.getDesc())) {
                submissionState = SubmissionCodeEnum.SUBMISSION_FAIL.getDesc();
            } else if (competitionSubmissionDO.getState().equals(SubmissionCodeEnum.SUBMISSION_SUCCESS.getDesc())) {
                submissionState = SubmissionCodeEnum.SUBMISSION_SUCCESS.getDesc();
            } else {
                submissionState = SubmissionCodeEnum.REVIEWING.getDesc();
            }
        }
        return submissionState;
    }

    private static String handleCompetitionState(List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS, String competitionState) {
        for (UserCompetitionRelationShipDO userCompetitionRelationShipDO : userCompetitionRelationShipDOS) {
            if (userCompetitionRelationShipDO.getState().equals(QuestionsEnum.QUESTIONS_FAIL.getDesc())) {
                competitionState = QuestionsEnum.QUESTIONS_FAIL.getDesc();
            } else if (userCompetitionRelationShipDO.getState().equals(QuestionsEnum.QUESTIONS_SUCCESS.getDesc())) {
                competitionState = QuestionsEnum.QUESTIONS_SUCCESS.getDesc();
            } else {
                competitionState = QuestionsEnum.REVIEWING.getDesc();
            }
        }
        return competitionState;
    }

    public Result questionsRegistration(ApplicationV2DTO applicationV2DTO) {
        String username = applicationV2DTO.getUsername();
        Integer competitionId = applicationV2DTO.getCompetitionId();
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectIsEnroll(username, competitionId);
        if (CollectionUtils.isNotEmpty(applicationV2DOList)) {
            return Result.error(ResultCodeEnum.ALREADY_APPLICATION);
        }
        if (applicationV2DTO.getUsername().equals("") || applicationV2DTO.getCompetitionParentId() == 0) {
            return Result.error(ResultCodeEnum.MUST_NOT_EXIST);
        }
        ApplicationV2DO applicationV2DO = new ApplicationV2DO();

        if (!ObjectUtils.isEmpty(applicationV2DTO.getAttachments())) {
            String path = FileUtils.saveMultipartFile(applicationV2DTO.getAttachments(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + applicationV2DTO.getUsername());
            applicationV2DO.setAttachments(path);
        }
        applicationV2DO.setUsername(applicationV2DTO.getUsername());
        applicationV2DO.setCompetitionParentId(applicationV2DTO.getCompetitionParentId());
        BeanUtils.copyProperties(applicationV2DTO, applicationV2DO);
        applicationV2DO.setStatus(REVIEWING.getCode());
        applicationV2DAO.insert(applicationV2DO);
        UserCompetitionRelationShipDO userCompetitionRelationShipDO = new UserCompetitionRelationShipDO();
        userCompetitionRelationShipDO.setUsername(applicationV2DTO.getUsername());
        userCompetitionRelationShipDO.setCompetitionId(applicationV2DTO.getCompetitionId());
        userCompetitionRelationShipDO.setState(QuestionsEnum.REVIEWING.getDesc());
        userCompetitionRelationShipDAO.insert(userCompetitionRelationShipDO);
        CompetitionDO competitionDO = competitionDAO.selectByCompetitionId(applicationV2DTO.getCompetitionId());
        MessageDO messageDO = new MessageDO();
        messageDO.setType(1);
        messageDO.setTitle("赛题报名消息");
        messageDO.setContent("您好!您的的" + competitionDO.getTitle() + "赛题报名成功");
        messageDO.setUsername(username);
        try {
            MessageUtils.sendMessage(username, sendMessageConfig.getQuestionApplication());
        }catch (Exception e){
                SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                smsErrLogDO.setPhone(username);
                smsErrLogDO.setType("赛题报名成功");
                smsErrLogDAO.insert(smsErrLogDO);
        }
        return Result.success(ResultCodeEnum.Enroll_Querstion_SUCEESS);
    }


    public Result questionSubmit(CompetitionSubmissionDTO competitionSubmissionDTO) {
        CompetitionSubmissionDO competitionSubmissionDO = new CompetitionSubmissionDO();
        competitionSubmissionDO.setCompetitionId(competitionSubmissionDTO.getCompetitionId());
        competitionSubmissionDO.setUsername(competitionSubmissionDTO.getUsername());
        competitionSubmissionDO.setState(SubmissionCodeEnum.REVIEWING.getDesc());
        if (!ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments()) && !ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments1())
                && !ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments2()) && !ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments3())) {
            String path = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            String path1 = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments1(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            String path2 = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments2(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            String path3 = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments3(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            competitionSubmissionDO.setAttachments(path);
            competitionSubmissionDO.setAttachments1(path1);
            competitionSubmissionDO.setAttachments2(path2);
            competitionSubmissionDO.setAttachments3(path3);
        }
        List<CompetitionSubmissionDO> competitionSubmissionDOS = competitionSubmissionDAO.selectByUsernameAndId(competitionSubmissionDTO.getUsername(), competitionSubmissionDTO.getCompetitionId());
        if(CollectionUtils.isEmpty(competitionSubmissionDOS)){
            competitionSubmissionDAO.insert(competitionSubmissionDO);
        }else {
            competitionSubmissionDAO.updateByUsername(competitionSubmissionDO);
        }
        MessageDO messageDO = new MessageDO();
        CompetitionDO competitionDO = competitionDAO.selectByCompetitionId(competitionSubmissionDTO.getCompetitionId());
        messageDO.setType(1);
        messageDO.setTitle("赛题报名消息");
        messageDO.setUsername(competitionSubmissionDTO.getUsername());
        messageDO.setContent("您好!您的的" + competitionDO.getTitle() + "赛题提交成功,请等待审核");
        try {
            MessageUtils.sendMessage(competitionSubmissionDTO.getUsername(), sendMessageConfig.getQuestionApplication());
        }catch (Exception e){
            SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
            smsErrLogDO.setPhone(competitionSubmissionDTO.getUsername());
            smsErrLogDO.setType("赛题提交成功");
            smsErrLogDAO.insert(smsErrLogDO);
        }
        return Result.success(ResultCodeEnum.Submit_QUerstion_SUCEESS);
    }

    public Result updateCompetition(UserCompetitionRelationShipDTO userCompetitionRelationShipDTO) {
        UserCompetitionRelationShipDO userCompetitionRelationShipDO = new UserCompetitionRelationShipDO();
        BeanUtils.copyProperties(userCompetitionRelationShipDTO, userCompetitionRelationShipDO);
        userCompetitionRelationShipDAO.updateByUserNameAndCompetitionId(userCompetitionRelationShipDO, userCompetitionRelationShipDTO.getUsername(), userCompetitionRelationShipDO.getCompetitionId());
        if (userCompetitionRelationShipDTO.getState().equals("赛题报名成功")) {
            MessageDO messageDO = new MessageDO();
            messageDO.setType(1);
            messageDO.setUsername(userCompetitionRelationShipDTO.getUsername());
            messageDO.setTitle("赛题报名消息");
            CompetitionDO competitionDO = competitionDAO.selectByCompetitionId(userCompetitionRelationShipDTO.getCompetitionId());
            messageDO.setContent("您好!您的+" + competitionDO.getTitle() + "报名审核成功");
            messageDAO.insert(messageDO);
            try {
                MessageUtils.sendMessage(userCompetitionRelationShipDTO.getUsername(), sendMessageConfig.getSuccessCompetition());
            }catch (Exception e){
                SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                smsErrLogDO.setPhone(userCompetitionRelationShipDTO.getUsername());
                smsErrLogDO.setType("赛题报名审核成功");
                smsErrLogDAO.insert(smsErrLogDO);
            }
        }
        if (userCompetitionRelationShipDTO.getState().equals("赛题报名失败")) {
            MessageDO messageDO = new MessageDO();
            messageDO.setType(1);
            messageDO.setUsername(userCompetitionRelationShipDTO.getUsername());
            messageDO.setTitle("赛题报名消息");
            CompetitionDO competitionDO = competitionDAO.selectByCompetitionId(userCompetitionRelationShipDTO.getCompetitionId());
            messageDO.setContent("您好!您的+" + competitionDO.getTitle() + "报名审核失败");
            messageDAO.insert(messageDO);
            try{
                MessageUtils.sendMessage(userCompetitionRelationShipDTO.getUsername(), sendMessageConfig.getFailCompetition());
            }catch (Exception e){
                SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                smsErrLogDO.setPhone(userCompetitionRelationShipDTO.getUsername());
                smsErrLogDO.setType("赛题报名审核失败");
                smsErrLogDAO.insert(smsErrLogDO);
            }
        }

        return Result.success(ResultCodeEnum.Update_Questions_SUCEESS);
    }

    public Result listApplication(PageRequest pageRequest) {




        IPage<ApplicationV2DO> applicationV2DOIPage = applicationV2DAO.selectAllByPage(pageRequest.getPagination());
        List<ApplicationV2DO> records = applicationV2DOIPage.getRecords();
        for (int i = 0; i < records.size(); i++) {
            List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByCompetitionId(records.get(i).getUsername(), records.get(i).getCompetitionId());
            if (!CollectionUtils.isEmpty(userCompetitionRelationShipDOS)) {
                UserCompetitionRelationShipDO userCompetitionRelationShipDO = userCompetitionRelationShipDOS.get(0);
                records.get(i).setStatus(userCompetitionRelationShipDO.getState());
            }
        }
        return Result.success(applicationV2DOIPage);
    }

    public Result vagueQuery(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String type = MapUtils.getString(params, "type");
        if(type.equals("")){
            IPage<ApplicationV2DO> applicationV2DOIPage = applicationV2DAO.selectUserByPage(pagination);
            List<ApplicationV2DO> records = applicationV2DOIPage.getRecords();
            for(int i=0;i<records.size();i++){
                List<CompetitionSubmissionDO> competitionSubmissionDOS = competitionSubmissionDAO.selectByUsernameAndId(records.get(i).getUsername(),records.get(i).getCompetitionId());
            }

            return Result.success();
        }
        if(type.equals("0")){
            String queryParam = MapUtils.getString(params, "username");
            return Result.success(applicationV2DAO.selectUserByCondition(pagination, queryParam));
        }else{
            String status = MapUtils.getString(params, "status");
            if(status.equals("0")){
                     IPage<ApplicationV2DO> applicationV2DOIPage=applicationV2DAO.selectWaitRelation(pagination);
                     return  Result.success(applicationV2DOIPage);
            }else  if(status.equals("1")){
                    IPage<ApplicationV2DO> applicationV2DOIPage = applicationV2DAO.selectPass(pagination);
                    return  Result.success(applicationV2DOIPage);

            }else {
                IPage<ApplicationV2DO> applicationV2DOIPage = applicationV2DAO.selectFail(pagination);
                return  Result.success(applicationV2DOIPage);
            }
        }
    }

    public Result listDemand(PageRequest pageRequest) {
        ArrayList<DemandVO> demandVOS = new ArrayList<>();
        IPage<DemandVO> demandVOIPage = new Page<DemandVO>();
        String type = MapUtils.getString(pageRequest.getParams(), "type");
        if(type.equals("0")){
            IPage<DemandDO> demandDOIPage = demandDAO.selectByAllPage(pageRequest.getPagination());
            listProducts(demandDOIPage, demandVOS,demandVOIPage);
        }else if(type.equals("1")){
            String demandName = MapUtils.getString(pageRequest.getParams(), "demandName");
            IPage<DemandDO> demandDOIPage = demandDAO.selectByDemandNamePage(pageRequest.getPagination(),demandName);
            listProducts(demandDOIPage, demandVOS,demandVOIPage);
        }else  if(type.equals("2")){
            String category = MapUtils.getString(pageRequest.getParams(), "category");
            IPage<DemandDO> demandDOIPage = demandDAO.selectByCategoryPage(pageRequest.getPagination(),category);
            listProducts(demandDOIPage, demandVOS,demandVOIPage);
        }else {
            String isShow = MapUtils.getString(pageRequest.getParams(), "isShow");
            IPage<DemandDO> demandDOIPage = demandDAO.selectByisShowPage(pageRequest.getPagination(),isShow);
            listProducts(demandDOIPage, demandVOS,demandVOIPage);
        }

        return Result.success(demandVOIPage);
    }

    private void listProducts( IPage<DemandDO> demandDOIPage, ArrayList<DemandVO> demandVOS, IPage<DemandVO> demandVOIPage) {
        List<DemandDO> records = demandDOIPage.getRecords();
        for(int i=0;i<records.size();i++){
            DemandVO demandVO = new DemandVO();
            List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(records.get(i).getUsername());
            if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
                demandVO.setEnterpriseCertificationDO(enterpriseCertificationDOS.get(0));
            }
            demandVO.setDemandDO(records.get(i));
            demandVOS.add(demandVO);
        }
        demandVOIPage.setRecords(demandVOS);
        demandVOIPage.setTotal(demandDOIPage.getTotal());
        demandVOIPage.setCurrent(demandDOIPage.getCurrent());
        demandVOIPage.setSize(demandDOIPage.getSize());
        demandVOIPage.setPages(demandDOIPage.getPages());
    }

    public Result deleteUser(UserDTO userDTO) {
        String username = userDTO.getUsername();
        userDAO.deleteByUsername(username);
        applicationV2DAO.deleteByUsername(username);
        userCompetitionRelationShipDAO.deleteByUsername(username);
        competitionSubmissionDAO.deleteByUsername(username);
        userAuthenticationDAO.deleteByUsername(username);
        enterpriseCertificationDAO.deleteByUsername(username);
        competitionChangeRecordDAO.deleteByUsername(username);
        demandDAO.deleteByUsername(username);
        messageDAO.deleteByUsername(username);
        singInRecordDAO.deleteByUsername(username);
        taskFinishDAO.deleteByUsername(username);
        return Result.success(ResultCodeEnum.USER_DELETE_SUCCESS);
    }

    public Result deleteByCompetitionId(ApplicationV2DTO applicationV2DTO) {
        applicationV2DAO.deleteByUsernameAndId(applicationV2DTO.getUsername(), applicationV2DTO.getCompetitionId(), applicationV2DTO.getCompetitionParentId());
        userCompetitionRelationShipDAO.deleteByUsernameAndCompetitionId(applicationV2DTO.getUsername(), applicationV2DTO.getCompetitionId());
        competitionSubmissionDAO.deleteByUsernameAndCompetitionId(applicationV2DTO.getUsername(), applicationV2DTO.getCompetitionId());
        return Result.success(ResultCodeEnum.USER_DELETE_SUCCESS);
    }

    public Result addProducts(DemandDTO demandDTO) {
        ArrayList<String> imagePaths = new ArrayList<>();
        ArrayList<String> outcomeInformation = new ArrayList<>();
        ArrayList<String> attachments = new ArrayList<>();
        DemandDO demandDO = new DemandDO();
        BeanUtils.copyProperties(demandDTO, demandDO);
        UserDO userDO = userDAO.selectByUsername(demandDTO.getUsername());
        if (userDO != null) {
            if (userDO.getIsAuthentication() == 0) {
                return Result.error(ResultCodeEnum.Unable_Finally_Authentication);
            }
        }
        DemandDO oldDemandName = demandDAO.selectByDemandName(demandDTO.getDemandName());
        DemandDO oldDemandContent = demandDAO.selectByContent(demandDTO.getProductOverview());
        if (oldDemandName != null||oldDemandContent!=null) {
            return Result.error(ResultCodeEnum.Product_EXIST);
        }
        if (demandDTO.getPicture() != null) {
            for (int i = 0; i < demandDTO.getPicture().size(); i++) {
                String image = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getPicture())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getPicture().get(i), devHttpPrefix+ DEMAND_PICTURE_PATH_PREFIX + image,
                            devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + image);
                    imagePaths.add(imagePath);
                }
                demandDO.setPicture(imagePaths);
            }
        }
        if (demandDTO.getAttachment() != null) {
            for (int i = 0; i < demandDTO.getAttachment().size(); i++) {
                String attachment = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getAttachment())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getAttachment().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + attachment,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + attachment);
                    attachments.add(imagePath);
                }
                demandDO.setAttachment(attachments);
            }
        }
        if (demandDTO.getOutcomeInformation() != null) {
            for (int i = 0; i < demandDTO.getOutcomeInformation().size(); i++) {
                String fileName = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getOutcomeInformation())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getOutcomeInformation().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + fileName,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + fileName);
                    outcomeInformation.add(imagePath);
                }
                demandDO.setOutcomeInformation(outcomeInformation);
            }
        }
        String videsName = ValidateCodeUtils.generateCode(4);
        if (!ObjectUtils.isEmpty(demandDTO.getProductVideos())) {
            String imagePath = FileUtils.saveMultipartFile2(demandDTO.getProductVideos(), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + videsName,
                    FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + videsName);
            demandDO.setProductVideos(imagePath);
        }
        demandDO.setIsShow(0);
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDTO.getUsername());
        if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
            demandDO.setCompanyName(enterpriseCertificationDOS.get(0).getEntName());
            demandDO.setCompanyAddress(enterpriseCertificationDOS.get(0).getMapAddress());
        }
        ArrayList<String> init = new ArrayList<>();
        demandDO.setPraiseUser(init);
        demandDO.setCollectionUser(init);
        demandDO.setShareUser(init);
        demandDAO.insert(demandDO);
        MessageDO messageDO = new MessageDO();
        messageDO.setType(1);
        messageDO.setTitle("上架产品消息");
        messageDO.setContent("您好!您的" + demandDTO.getDemandName() + "产品上架成功,请等待审核!");
        messageDAO.insert(messageDO);
        try{
        MessageUtils.sendMessage(demandDTO.getUsername(),sendMessageConfig.getShelvesProducts());
        }catch (Exception e){
            SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
            smsErrLogDO.setPhone(demandDTO.getUsername());
            smsErrLogDO.setType("产品上架审核");
            smsErrLogDAO.insert(smsErrLogDO);
        }
        return Result.success();
    }

    public Result showProducts(PageRequest pageRequest) {
        IPage<DemandDO> demandDOIPage=new Page<>();
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String demandName = MapUtils.getString(params, "demandName");
        String category = MapUtils.getString(params, "category");
        //根据浏览量排序
        String showNumber = MapUtils.getString(params, "showNumber");
        //根据点赞排序
        String praise = MapUtils.getString(params, "praise");
        //根据收藏排序
        String collection = MapUtils.getString(params, "collection");
        if (!category.equals("")) {
            if (demandName.equals("")) {
                if (showNumber.equals("") && praise.equals("") && collection.equals("")) {
                     demandDOIPage = demandDAO.selectByPageAndCatgory(pagination, category);
                    return Result.success(demandDOIPage);
                } else if (showNumber.equals("1") && praise.equals("") && collection.equals("")) {
                     demandDOIPage = demandDAO.selectByPageAndCatgoryShowNumberDesc(pagination, category);
                    return Result.success(demandDOIPage);
                } else if (showNumber.equals("0") && praise.equals("") && collection.equals("")) {
                    demandDOIPage = demandDAO.selectByPageAndCatgoryShowNumberASC(pagination, category);
                    return Result.success(demandDOIPage);
                } else if (showNumber.equals("") && praise.equals("1") && collection.equals("")) {
                     demandDOIPage = demandDAO.selectByPageAndCatgoryPraiseDesc(pagination, category);
                    return Result.success(demandDOIPage);
                }else if (showNumber.equals("") && praise.equals("0") && collection.equals("")) {
                    demandDOIPage = demandDAO.selectByPageAndCatgoryPraiseASC(pagination, category);
                    return Result.success(demandDOIPage);
                }else if (showNumber.equals("") && praise.equals("") && collection.equals("1")) {
                    demandDOIPage = demandDAO.selectByPageAndCatgoryCollectionDesc(pagination, category);
                    return Result.success(demandDOIPage);
                }else if (showNumber.equals("") && praise.equals("") && collection.equals("0")) {
                   demandDOIPage = demandDAO.selectByPageAndCatgoryCollectionASC(pagination, category);
                    return Result.success(demandDOIPage);
                }
            }

            if (showNumber.equals("") && praise.equals("") && collection.equals("")) {
               demandDOIPage = demandDAO.selectByPageAndLike(pagination, demandName, category);
                return Result.success(demandDOIPage);
            } else if (showNumber.equals("1") && praise.equals("") && collection.equals("")) {
               demandDOIPage = demandDAO.selectByPageAndLikeShowNubmerDesc(pagination, demandName, category);
                return Result.success(demandDOIPage);
            } else if (showNumber.equals("0") && praise.equals("") && collection.equals("")) {
               demandDOIPage = demandDAO.selectByPageAndLikeShowNubmerASC(pagination, demandName, category);
                return Result.success(demandDOIPage);
            } else if (showNumber.equals("") && praise.equals("1") && collection.equals("")) {
              demandDOIPage = demandDAO.selectByPageAndLikePraiseDesc(pagination, demandName, category);
                return Result.success(demandDOIPage);
            }else if (showNumber.equals("") && praise.equals("0") && collection.equals("")) {
               demandDOIPage = demandDAO.selectByPageAndLikePraiseASC(pagination, demandName, category);
                return Result.success(demandDOIPage);
            }else if (showNumber.equals("") && praise.equals("") && collection.equals("1")) {
                demandDOIPage = demandDAO.selectByPageAndLikeCollectionDesc(pagination, demandName, category);
                return Result.success(demandDOIPage);
            }else if (showNumber.equals("") && praise.equals("") && collection.equals("0")) {
                demandDOIPage = demandDAO.selectByPageAndLikeCollectionASC(pagination, demandName, category);
                return Result.success(demandDOIPage);
            }
        } else {
            if (demandName.equals("")) {
                if (showNumber.equals("") && praise.equals("") && collection.equals("")) {
                    demandDOIPage = demandDAO.selectByPage(pagination);
                    return Result.success(demandDOIPage);
                } else if (showNumber.equals("1") && praise.equals("") && collection.equals("")) {
                    demandDOIPage = demandDAO.selectByPageAndShowNumberDesc(pagination);
                    return Result.success(demandDOIPage);
                } else if (showNumber.equals("0") && praise.equals("") && collection.equals("")) {
                     demandDOIPage = demandDAO.selectByPageAndShowNumberASC(pagination);
                    return Result.success(demandDOIPage);
                } else if (showNumber.equals("") && praise.equals("1") && collection.equals("")) {
                     demandDOIPage = demandDAO.selectByPageAndPraiseDesc(pagination);
                    return Result.success(demandDOIPage);
                }else if (showNumber.equals("") && praise.equals("0") && collection.equals("")) {
                   demandDOIPage = demandDAO.selectByPageAndPraiseASC(pagination);
                    return Result.success(demandDOIPage);
                }else if (showNumber.equals("") && praise.equals("") && collection.equals("1")) {
                    demandDOIPage = demandDAO.selectByPageAndCollectionDesc(pagination);
                    return Result.success(demandDOIPage);
                }else if (showNumber.equals("") && praise.equals("") && collection.equals("0")) {
                   demandDOIPage = demandDAO.selectByPageAndCollectionASC(pagination);
                    return Result.success(demandDOIPage);
                }
            }
            demandDOIPage = demandDAO.selectByPageAndLike2(pagination, demandName);
        }

        return Result.success(demandDOIPage);
    }

    private List<DemandDO> convertDTO(List<UserDemandDO> collect) {
        List<DemandDO> demandDOS = new ArrayList<>();
        for (int i = 0; i < collect.size(); i++) {
            DemandDO demandDO = new DemandDO();
            BeanUtils.copyProperties(collect.get(i), demandDO);
            demandDOS.add(demandDO);
        }
        return demandDOS;
    }

    public Result updateUser(UserInfoDTO userInfoDTO) {
        UserDO userDO = new UserDO();
        ArrayList<String> posters = new ArrayList<>();
        UserAuthenticationDO userAuthenticationDO = new UserAuthenticationDO();
        EnterpriseCertificationDO enterpriseCertificationDO = new EnterpriseCertificationDO();
        userAuthenticationDO.setPhone(userInfoDTO.getUsername());
        enterpriseCertificationDO.setPhoneNumber(userInfoDTO.getUsername());
        BeanUtils.copyProperties(userInfoDTO, userDO);
        BeanUtils.copyProperties(userInfoDTO, userAuthenticationDO);
        BeanUtils.copyProperties(userInfoDTO, enterpriseCertificationDO);
        if (!ObjectUtils.isEmpty(userInfoDTO.getAvatar())) {
            String path = FileUtils.saveMultipartFile2(userInfoDTO.getAvatar(),
                    devHttpPrefix + RESOURCE_PATH_PREFIX + userInfoDTO.getUsername(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + userInfoDTO.getUsername());
            userDO.setAvatar(path);
        }
        if (!ObjectUtils.isEmpty(userInfoDTO.getBackground())) {
            String path = FileUtils.saveMultipartFile2(userInfoDTO.getBackground(),
                    devHttpPrefix + RESOURCE_PATH_PREFIX + userInfoDTO.getId(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + userInfoDTO.getId());
            userDO.setBackground(path);
            userAuthenticationDO.setBackground(path);
        }
        if (!ObjectUtils.isEmpty(userInfoDTO.getLogo())) {
            String path = FileUtils.saveMultipartFile2(userInfoDTO.getLogo(),
                    devHttpPrefix + RESOURCE_PATH_PREFIX + userInfoDTO.getEntName(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + userInfoDTO.getEntName());
            enterpriseCertificationDO.setLogo(path);
        }
        if (!ObjectUtils.isEmpty(userInfoDTO.getPosters())) {
            for (int i = 0; i < userInfoDTO.getPosters().size(); i++) {
                {
                    String fileName = ValidateCodeUtils.generateCode(4);
                    String imagePath = FileUtils.saveMultipartFile2(userInfoDTO.getPosters().get(i),
                            devHttpPrefix + RESOURCE_PATH_PREFIX + fileName,
                            FileUtils.staticPath + RESOURCE_PATH_PREFIX + fileName);
                    posters.add(imagePath);
                }
            }
            enterpriseCertificationDO.setPosters(posters);
        }
        userDAO.updateByUserName(userDO);
        userAuthenticationDAO.updateByUserName(userAuthenticationDO);
        enterpriseCertificationDAO.updateByPhoneNumber(enterpriseCertificationDO);
        return Result.success("修改成功");
    }


    public Result checkQuestions(ApplicationV2DTO applicationV2DTO) {
        String username = applicationV2DTO.getUsername();
        if (username.equals("")) {
            return Result.error(ResultCodeEnum.UNSIGNED_USER);
        }
        UserDO userDO = userDAO.selectByUsername(username);
        if (userDO != null) {
            Integer isAuthentication = userDO.getIsAuthentication();
            if (isAuthentication == 0) {
                return Result.error(ResultCodeEnum.Unable_Finally_Authentication);
            } else {
                List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByCompetitionId(username, applicationV2DTO.getCompetitionId());
                if (CollectionUtils.isEmpty(userCompetitionRelationShipDOS)) {
                    return Result.success(ResultCodeEnum.SUCCESS);
                } else {
                    return Result.error(ResultCodeEnum.HAVE_SELECT_QUerstion);
                }

            }
        } else {
            return Result.error(ResultCodeEnum.NO_REGISTER);
        }
    }

    public Result updateProducts(DemandDTO demandDTO) {
        AgencyProductRelationshipsDO agencyProductRelationshipsDO = agencyProductRelationshipsDAO.selectByProductId(demandDTO.getId());
        ArrayList<String> imagePaths = new ArrayList<>();
        ArrayList<String> outcomeInformation = new ArrayList<>();
        ArrayList<String> attachments = new ArrayList<>();
        DemandDO demandDO = new DemandDO();
        BeanUtils.copyProperties(demandDTO, demandDO);
        DemandRecordDO demandRecordDO = new DemandRecordDO();
        demandRecordDO.setProductId(demandDTO.getId());
        demandRecordDO.setUsername(demandDTO.getReviewer());
        demandRecordDO.setOperate("修改产品");
        demandRecordDAO.insert(demandRecordDO);
        if (demandDTO.getAttachment() != null) {
            for (int i = 0; i < demandDTO.getAttachment().size(); i++) {
                String attachment = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getAttachment())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getAttachment().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + attachment,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + attachment);
                    attachments.add(imagePath);
                }
                demandDO.setAttachment(attachments);
            }
        }

        if (demandDTO.getPicture() != null) {
            for (int i = 0; i < demandDTO.getPicture().size(); i++) {
                String image = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getPicture())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getPicture().get(i), devHttpPrefix+ DEMAND_PICTURE_PATH_PREFIX + image,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
                    imagePaths.add(imagePath);
                }
            }
            demandDO.setPicture(imagePaths);

        }

        if (demandDTO.getOutcomeInformation() != null) {
            for (int i = 0; i < demandDTO.getOutcomeInformation().size(); i++) {
                String fileName = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getOutcomeInformation())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getOutcomeInformation().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + fileName,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + fileName);
                    outcomeInformation.add(imagePath);
                }
            }
            demandDO.setOutcomeInformation(outcomeInformation);

        }
        String videsName = ValidateCodeUtils.generateCode(4);
        if (!ObjectUtils.isEmpty(demandDTO.getProductVideos())) {
            String imagePath = FileUtils.saveMultipartFile2(demandDTO.getProductVideos(), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + videsName,
                    FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + videsName);
            demandDO.setProductVideos(imagePath);
        }
        if(demandDTO.getIsShow()==null){
             demandDO.setIsShow(0);
        }
        boolean b = demandDAO.updateById(demandDO);
        personalRecommendationsDAO.deleteByUsernameAndId(demandDTO.getUsername(),demandDTO.getId());
        if(demandDTO.getIsShow()!=null){
            if(demandDTO.getIsShow()==1){
                if(agencyProductRelationshipsDO!=null){
                    agencyProductRelationshipsDO.setProductState("已上架");
                    agencyProductRelationshipsDAO.updateById(agencyProductRelationshipsDO);
                }
                MessageDO messageDO = new MessageDO();
                messageDO.setType(1);
                messageDO.setTitle("上架产品消息");
                messageDO.setContent("您好!您的" + demandDTO.getDemandName() + "产品上架审核通过!");
                messageDO.setUsername(demandDTO.getUsername());
                messageDAO.insert(messageDO);
                TaskTagDO taskTagDO=taskTagDAO.selectByProductTaskName();
                TaskFinishDO taskFinishDO =taskFinishDAO.selecByTaskAndUser(taskTagDO.getId(),demandDTO.getUsername());
                if(taskFinishDO!=null){
                    //没有上架过产品才会加积分
                    PointBreakdownDO pointBreakdownDO = new PointBreakdownDO();
                    pointBreakdownDO.setType(productType);
                    pointBreakdownDO.setUsername(demandDTO.getUsername());
                    pointBreakdownDO.setDetails("上架产品"+demandDTO.getDemandName()+",获得"+productPoint+"积分");
                    pointBreakdownDO.setPoint("+"+productPoint);
                    UserDO userDO = userDAO.selectByUsername(demandDTO.getUsername());
                    userDO.setPoints(userDO.getPoints()+productPoint);
                    userDAO.updateById(userDO);
                    taskFinishDO.setIsFinish(1);
                    pointBreakdownDAO.insert(pointBreakdownDO);
                    taskFinishDAO.updateById(taskFinishDO);
                }
                try {
                    MessageUtils.sendMessage(demandDTO.getUsername(), sendMessageConfig.getSuccessProducts());
                }catch (Exception e){
                    SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                    smsErrLogDO.setPhone(demandDTO.getUsername());
                    smsErrLogDO.setType("上架产品审核通过");
                    smsErrLogDAO.insert(smsErrLogDO);
                }
            }
            if(demandDTO.getIsShow()==-1){
                if(agencyProductRelationshipsDO!=null){
                    agencyProductRelationshipsDO.setRemark(demandDTO.getFeedback());
                    agencyProductRelationshipsDO.setProductState("上架失败");
                    agencyProductRelationshipsDAO.updateById(agencyProductRelationshipsDO);
                }
                MessageDO messageDO = new MessageDO();
                messageDO.setType(1);
                messageDO.setTitle("上架产品消息");
                messageDO.setContent("您好!您的" + demandDTO.getDemandName() + "产品上架审核失败,请修改产品信息重试!失败原因为:"+demandDTO.getFeedback());
                messageDO.setUsername(demandDTO.getUsername());
                messageDAO.insert(messageDO);
                try{
                    MessageUtils.sendMessage(demandDTO.getUsername(),sendMessageConfig.getFailProducts());
                }catch(Exception e){
                    SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                    smsErrLogDO.setPhone(demandDTO.getUsername());
                    smsErrLogDO.setType("上架产品审核失败");
                    smsErrLogDAO.insert(smsErrLogDO);
                }

            }
        }
        if (b) {
            return Result.success(ResultCodeEnum.SUCCESS_UPDATE_Products);
        }
        return Result.success(ResultCodeEnum.Fail_UPDATE_Products);
    }

    public Result deleteProducts(Integer id) {
        DemandDO demandDO = demandDAO.selectById(id);
        DeleteDemandDO deleteDemandDO = new DeleteDemandDO();
        BeanUtils.copyProperties(demandDO,deleteDemandDO);
        MessageDO messageDO = new MessageDO();
        messageDO.setType(1);
        messageDO.setTitle("上架产品消息");
        messageDO.setUsername(demandDO.getUsername());
        messageDO.setContent("您好!您的" + demandDO.getDemandName() + "产品已经被删除!");
        messageDAO.insert(messageDO);
        boolean b1 = demandDAO.deleteById(id);
        deleteDemandDAO.insert(deleteDemandDO);
        try{
            MessageUtils.sendMessage(messageDO.getUsername(),sendMessageConfig.getDeleteProduct());
        }catch (Exception e){
            SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
            smsErrLogDO.setPhone(messageDO.getUsername());
            smsErrLogDO.setType("产品已经被删除");
        }
        if (b1) {
            return Result.success(ResultCodeEnum.SUCCESS_DELETE_Products);
        }
        return Result.error(ResultCodeEnum.Fail_DELETE_Products);
    }

    public Result uploadCertification(EnterpriseCertificationDTO enterpriseCertificationDTO) {
        ArrayList<String> posters = new ArrayList<>();
        MessageDO messageDO = new MessageDO();
        messageDO.setType(1);
        messageDO.setTitle("企业认证消息");
        messageDO.setContent("您好!您的" + enterpriseCertificationDTO.getEntName() + "认证在审核中!");
        messageDO.setUsername(enterpriseCertificationDTO.getUsername());
        messageDAO.insert(messageDO);
        try {
            MessageUtils.sendMessage(enterpriseCertificationDTO.getUsername(),sendMessageConfig.getEnterpriseCertification());
        }catch (Exception e){
            SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
            smsErrLogDO.setPhone(enterpriseCertificationDTO.getUsername());
            smsErrLogDO.setType("第二种:企业认证");
            smsErrLogDAO.insert(smsErrLogDO);
        }

        EnterpriseCertificationDO enterpriseCertificationDO = new EnterpriseCertificationDO();
        BeanUtils.copyProperties(enterpriseCertificationDTO, enterpriseCertificationDO);
        if (!ObjectUtils.isEmpty(enterpriseCertificationDTO.getLogo())) {
            String logo = FileUtils.saveMultipartFile2(enterpriseCertificationDTO.getLogo(), devHttpPrefix + RESOURCE_PATH_PREFIX + enterpriseCertificationDTO.getEntName(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + enterpriseCertificationDTO.getEntName());
            enterpriseCertificationDO.setLogo(logo);
        } else {
            enterpriseCertificationDO.setLogo("https://nism.ytcata.com:3005/static/resource/2313/adf2c538802bee9458509e0dea614f7.jpg");
        }
        if (!ObjectUtils.isEmpty(enterpriseCertificationDTO.getPosters())) {
            for (int i = 0; i < enterpriseCertificationDTO.getPosters().size(); i++) {
                {
                    String fileName = ValidateCodeUtils.generateCode(4);
                    String imagePath = FileUtils.saveMultipartFile2(enterpriseCertificationDTO.getPosters().get(i), devHttpPrefix + RESOURCE_PATH_PREFIX + fileName,
                            FileUtils.staticPath + RESOURCE_PATH_PREFIX + fileName);
                    posters.add(imagePath);
                }
            }
            enterpriseCertificationDO.setPosters(posters);
        } else {
            String poster = "https://nism.ytcata.com:3005/static/resource/3KKb/91f79f13b90165194f338ee291f8471.jpg";
            posters.add(poster);
            enterpriseCertificationDO.setPosters(posters);
        }
        if (!ObjectUtils.isEmpty(enterpriseCertificationDTO.getAttachment())) {
            String imagePath = FileUtils.saveMultipartFile(enterpriseCertificationDTO.getAttachment(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + enterpriseCertificationDTO.getEntName());
            enterpriseCertificationDO.setAttachment(imagePath);
        }
        if(!ObjectUtils.isEmpty(enterpriseCertificationDTO.getLicense())) {
            String fileName=ValidateCodeUtils.generateCode(4);
            String licence = FileUtils.saveMultipartFile2(enterpriseCertificationDTO.getLicense(), devHttpPrefix + RESOURCE_PATH_PREFIX + fileName,
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX +fileName);
            enterpriseCertificationDO.setLicense(licence);
        }
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(enterpriseCertificationDTO.getPhoneNumber());
        if (CollectionUtils.isEmpty(enterpriseCertificationDOS)) {
            enterpriseCertificationDAO.insert(enterpriseCertificationDO);
        }

        enterpriseCertificationDAO.updateByPhoneNumber(enterpriseCertificationDO);
        UserDO userDO = userDAO.selectByUsername(enterpriseCertificationDTO.getUsername());
        if(userDO!=null){
            userDO.setCertificationResults(0);
            userDO.setMapAddress(enterpriseCertificationDTO.getMapAddress());
            userDAO.updateById(userDO);
        }
        return Result.success(ResultCodeEnum.Company_upload_SUCCESS);
    }

    public Result listCertification() {
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> !ObjectUtils.isEmpty(item.getAttachment())).collect(Collectors.toList());
        return Result.success(collect);
    }

    public Result updateCertification(EnterpriseCertificationDTO enterpriseCertificationDTO) {
        EnterpriseCertificationDO enterpriseCertificationDO = new EnterpriseCertificationDO();
        BeanUtils.copyProperties(enterpriseCertificationDTO, enterpriseCertificationDO);
        enterpriseCertificationDAO.updateByPhoneNumber(enterpriseCertificationDO);
        UserDO userDO = userDAO.selectByUsername(enterpriseCertificationDTO.getPhoneNumber());
        userDO.setCertificationResults(enterpriseCertificationDTO.getCertificationResults());
        userDAO.updateById(userDO);
        if (userDO != null) {
            if (enterpriseCertificationDTO.getCertificationResults() == 1) {
                userDO.setIsAuthentication(1);
                userDO.setAuthenticationType("企业认证");
                userDO.setEntName(enterpriseCertificationDTO.getEntName());
                userDO.setIsEnterpriseCertification(1);
                userDO.setPoints(userDO.getPoints()+EntPoint);
                userDAO.updateById(userDO);
                MessageDO messageDO = new MessageDO();
                messageDO.setType(1);
                messageDO.setTitle("企业认证消息");
                messageDO.setContent("您好!您的" + enterpriseCertificationDTO.getEntName() + "认证在审核通过!");
                messageDO.setUsername(userDO.getUsername());
                messageDAO.insert(messageDO);
                PointBreakdownDO pointBreakdownDO = new PointBreakdownDO();
                pointBreakdownDO.setType(EntType);
                pointBreakdownDO.setUsername(enterpriseCertificationDTO.getPhoneNumber());
                pointBreakdownDO.setDetails("企业认证,获得"+EntPoint+"积分");
                pointBreakdownDO.setPoint("+"+EntPoint);
                pointBreakdownDAO.insert(pointBreakdownDO);
                TaskTagDO taskTagDO=taskTagDAO.selectByEntTaskName();
                TaskFinishDO taskFinishDO = taskFinishDAO.selecByTaskAndUser(taskTagDO.getId(), enterpriseCertificationDTO.getPhoneNumber());
                if(taskFinishDO!=null){
                    taskFinishDO.setIsFinish(1);
                    taskFinishDAO.updateById(taskFinishDO);
                }
                MessageUtils.sendMessage(enterpriseCertificationDTO.getPhoneNumber(),sendMessageConfig.getEnterpriseCertificationSuccess());
            } else {
                MessageDO messageDO = new MessageDO();
                messageDO.setType(1);
                messageDO.setTitle("企业认证消息");
                messageDO.setContent("您好!您的" + enterpriseCertificationDTO.getEntName() + "认证在审核失败!");
                messageDO.setUsername(userDO.getUsername());
                messageDAO.insert(messageDO);
                MessageUtils.sendMessage(enterpriseCertificationDTO.getPhoneNumber(),sendMessageConfig.getEnterpriseCertificationFailed());
                userDO.setIsAuthentication(0);
                userDO.setAuthenticationType("");
                userDO.setIsEnterpriseCertification(0);
                userDAO.updateById(userDO);
            }
        }
        return Result.success(ResultCodeEnum.Company_Update_SUCCESS);
    }

    public Result listUser(PageRequest pageRequest) {
        Map<String, Object> params = pageRequest.getParams();
        String type = MapUtils.getString(params, "type");
        if(type.equals("0")){
            IPage<UserDO> userDOIPage = userDAO.selectByPage(pageRequest.getPagination());
            return Result.success(userDOIPage);
        }
        else if(type.equals("1")){
            //用户名
            String username = MapUtils.getString(params, "username");
            IPage<UserDO> userDOIPage = userDAO.selectByPageByName(pageRequest.getPagination(),username);
            return Result.success(userDOIPage);
        }else if(type.equals("2")){
            //企业名
            String entName = MapUtils.getString(params, "entName");
            IPage<EnterpriseCertificationDO> enterpriseCertificationDOIPage = enterpriseCertificationDAO.selectByPageByEntName(pageRequest.getPagination(),entName);
            return Result.success(enterpriseCertificationDOIPage);
        }else  if(type.equals("3")){
            //个人名
            String individualName = MapUtils.getString(params, "individualName");
            IPage<UserAuthenticationDO> userAuthenticationDOPage = userAuthenticationDAO.selectByName(pageRequest.getPagination(), individualName);
            return Result.success(userAuthenticationDOPage);
        }else if(type.equals("4")){
            //昵称
            String nickname = MapUtils.getString(params, "nickname");
            IPage<UserDO> userDOIPage = userDAO.selectByPageByNickName(pageRequest.getPagination(),nickname);
            return Result.success(userDOIPage);
        }else {
            //认证
            String authentication = MapUtils.getString(params, "authentication");
            if(authentication.equals("0")){
                IPage<UserDO> userDOIPage = userDAO.selectByPageByWaitAuthentication(pageRequest.getPagination());
                return  Result.success(userDOIPage);
            }
            else if(authentication.equals("-1")){
                IPage<UserDO> userDOIPage = userDAO.selectByPageByNotAuthentication(pageRequest.getPagination());
                return  Result.success(userDOIPage);
            }else if(authentication.equals("1")){
                IPage<UserDO> userDOIPage = userDAO.selectByPageBySuccessAuthentication(pageRequest.getPagination());
                return  Result.success(userDOIPage);
            }else {
                IPage<UserDO> userDOIPage = userDAO.selectByPageByFailAuthentication(pageRequest.getPagination());
                return Result.success(userDOIPage);
            }
        }
    }

    public Result detailProduct(Integer id, Integer type) {
        DemandVO demandVO = new DemandVO();
        if(type==0){
            DemandDO demandDO = demandDAO.selectById(id);
            if(demandDO.getIsShow()!=1){
                DemandVO demandVO1 = new DemandVO();
                return  Result.success(ResultCodeEnum.NO_DATA,demandVO1);
            }
            Integer showNumber = demandDO.getShowNumber();
            demandDO.setShowNumber(++showNumber);
            demandDAO.updateById(demandDO);
            if(demandDO.getIsPublic()==1){
                List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDO.getUsername());
                if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
                    demandVO.setEnterpriseCertificationDO(enterpriseCertificationDOS.get(0));
                }
            }
            demandVO.setDemandDO(demandDO);
            List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDO.getUsername());
            if (!CollectionUtils.isEmpty(enterpriseCertificationDOS)) {
                demandVO.setPosters(enterpriseCertificationDOS.get(0).getPosters());
                String poster = "https://nism.ytcata.com:3005/static/resource/3KKb/91f79f13b90165194f338ee291f8471.jpg";
                ArrayList<String> posters = new ArrayList<>();
                posters.add(poster);
                demandVO.setPosters(posters);
                return Result.success(demandVO);
            }
        }else {
            DemandDO demandDO = demandDAO.selectById(id);
            if(demandDO.getIsPublic()==1){
                List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDO.getUsername());
                if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
                    demandVO.setEnterpriseCertificationDO(enterpriseCertificationDOS.get(0));
                }
            }
            demandVO.setDemandDO(demandDO);
            List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDO.getUsername());
            if (!CollectionUtils.isEmpty(enterpriseCertificationDOS)) {
                demandVO.setPosters(enterpriseCertificationDOS.get(0).getPosters());
                String poster = "https://nism.ytcata.com:3005/static/resource/3KKb/91f79f13b90165194f338ee291f8471.jpg";
                ArrayList<String> posters = new ArrayList<>();
                posters.add(poster);
                demandVO.setPosters(posters);
                return Result.success(demandVO);
            }
        }
        return  Result.success(demandVO);
    }


    public Result addUserProducts(DemandDTO demandDTO) {
            ArrayList<String> imagePaths = new ArrayList<>();
            ArrayList<String> outcomeInformation = new ArrayList<>();
            ArrayList<String> attachments = new ArrayList<>();
            DemandDO demandDO = new DemandDO();
            BeanUtils.copyProperties(demandDTO, demandDO);
            UserDO userDO = userDAO.selectByUsername(demandDTO.getUsername());
            if (userDO != null) {
                if (userDO.getIsAuthentication() == 0) {
                    return Result.error(ResultCodeEnum.Unable_Finally_Authentication);
                }
            }
            DemandDO oldDemandName = demandDAO.selectByDemandName(demandDTO.getDemandName());
            DemandDO oldDemandContent = demandDAO.selectByContent(demandDTO.getProductOverview());
            if (oldDemandName != null&&oldDemandContent!=null) {
                return Result.error(ResultCodeEnum.Product_EXIST);
            }
            if (demandDTO.getPicture() != null) {
                for (int i = 0; i < demandDTO.getPicture().size(); i++) {
                    String image = ValidateCodeUtils.generateCode(4);
                    if (!ObjectUtils.isEmpty(demandDTO.getPicture())) {
                        String imagePath = FileUtils.saveMultipartFile2(demandDTO.getPicture().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + image,
                                FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
                        imagePaths.add(imagePath);
                        System.out.println(image);
                    }
                    demandDO.setPicture(imagePaths);
                }
            }
            if (demandDTO.getAttachment() != null) {
                for (int i = 0; i < demandDTO.getAttachment().size(); i++) {
                    String attachment = ValidateCodeUtils.generateCode(4);
                    if (!ObjectUtils.isEmpty(demandDTO.getAttachment())) {
                        String imagePath = FileUtils.saveMultipartFile2(demandDTO.getAttachment().get(i), FileUtils.httpPrefix + DEMAND_PICTURE_PATH_PREFIX + attachment,
                                FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + attachment);
                        attachments.add(imagePath);
                    }
                    demandDO.setAttachment(attachments);
                }
            }
            if (demandDTO.getOutcomeInformation() != null) {
                for (int i = 0; i < demandDTO.getOutcomeInformation().size(); i++) {
                    String fileName = ValidateCodeUtils.generateCode(4);
                    if (!ObjectUtils.isEmpty(demandDTO.getOutcomeInformation())) {
                        String imagePath = FileUtils.saveMultipartFile2(demandDTO.getOutcomeInformation().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + fileName,
                                FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + fileName);
                        outcomeInformation.add(imagePath);
                    }
                    demandDO.setOutcomeInformation(outcomeInformation);
                }
            }
            String videsName = ValidateCodeUtils.generateCode(4);
            if (!ObjectUtils.isEmpty(demandDTO.getProductVideos())) {
                String imagePath = FileUtils.saveMultipartFile2(demandDTO.getProductVideos(), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + videsName,
                        FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + videsName);
                demandDO.setProductVideos(imagePath);
            }
            demandDO.setIsShow(0);
            List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDTO.getUsername());
            if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
                demandDO.setCompanyName(enterpriseCertificationDOS.get(0).getEntName());
                demandDO.setCompanyAddress(enterpriseCertificationDOS.get(0).getMapAddress());

            }
            ArrayList<String> init = new ArrayList<>();
            demandDO.setPraiseUser(init);
            demandDO.setCollectionUser(init);
            demandDO.setShareUser(init);
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DeleteDemandDO> deleteDemandDOS = deleteDemandDAO.selectAll();
        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getCategory().equals(demandDTO.getCategory())).collect(Collectors.toList());
        List<DeleteDemandDO> collect1 = deleteDemandDOS.stream().filter(item -> item.getCategory().equals(demandDTO.getCategory())).collect(Collectors.toList());
        String serialNumber = makeSerialNumber(demandDTO.getCategory(),collect.size()+collect1.size());
            demandDO.setSerialNumber(serialNumber);
            demandDAO.insert(demandDO);
            List<StagingProductDO> stagingProductDOS = stagingProductDAO.selectByDemandName(demandDTO.getDemandName());
            if(!CollectionUtils.isEmpty(stagingProductDOS)){
                for(StagingProductDO stagingProductDO:stagingProductDOS){
                    stagingProductDAO.deleteById(stagingProductDO.getId());
                }
            }
            MessageDO messageDO = new MessageDO();
            messageDO.setType(1);
            messageDO.setUsername(demandDTO.getUsername());
            messageDO.setTitle("上架产品消息");
            messageDO.setContent("您好!您的" + demandDTO.getDemandName() + "产品上架成功,请等待审核!");
            messageDAO.insert(messageDO);
            MessageUtils.sendMessage(demandDTO.getUsername(),sendMessageConfig.getShelvesProducts());
            return Result.success();
    }
    public  String  makeSerialNumber(String category,Integer size){
        String sid = ValidateCodeUtils.fillString(size, 3);
        String serialNumber="";
       if(category.equals("人工智能")){
           serialNumber="RG";
       }
        else  if(category.equals("机器人")){
            serialNumber="JQR";
        }
       else if(category.equals("大数据")){
            serialNumber="SJ";
        }
       else if(category.equals("智能设备")){
            serialNumber="ZN";
        }
       else if(category.equals("通信工程")){
           serialNumber="TX";
       }
       else if(category.equals("系统软件")){
           serialNumber="XT";
       }
       else if(category.equals("移动应用")){
           serialNumber="YD";
       }
       else if(category.equals("其他")){
           serialNumber="QT";
       }
       serialNumber=serialNumber+"-"+sid;

        return  serialNumber;
    }

    public Result showUserProducts(PageRequest pageRequest) {
        Map<String, Object> params = pageRequest.getParams();
        String username = MapUtils.getString(params, "username");
        String isShow = MapUtils.getString(params, "isShow");
        String demandName = MapUtils.getString(params, "demandName");
        if (isShow.equals("")) {
            if (demandName.equals("")) {
                IPage<DemandDO> DemandDOIPage = demandDAO.selectByPageAndUserName(pageRequest.getPagination(), username);
                return Result.success(DemandDOIPage);
            } else {
                IPage<DemandDO> DemandDOIPage = demandDAO.selectByPageAndDemandName(pageRequest.getPagination(), username, demandName);
                return Result.success(DemandDOIPage);
            }

        } else {
            if (demandName.equals("")) {
                IPage<DemandDO> DemandDOIPage = demandDAO.selectByPageAndShow(pageRequest.getPagination(), username, isShow);
                return Result.success(DemandDOIPage);
            } else {
                IPage<DemandDO> DemandDOIPage = demandDAO.selectByPageAndDemandNameAndShow(pageRequest.getPagination(), username, demandName, isShow);
                return Result.success(DemandDOIPage);
            }
        }

    }

    public Result updateQuestionSubmit(CompetitionSubmissionDTO competitionSubmissionDTO) {
        CompetitionSubmissionDO competitionSubmissionDO = new CompetitionSubmissionDO();
        BeanUtils.copyProperties(competitionSubmissionDTO, competitionSubmissionDO);
        if (!ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments())) {
            String imagePath = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            competitionSubmissionDO.setAttachments(imagePath);
        }
        if (!ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments1())) {
            String imagePath1 = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments1(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            competitionSubmissionDO.setAttachments1(imagePath1);
        }
        if (!ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments2())) {
            String imagePath2 = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments2(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            competitionSubmissionDO.setAttachments2(imagePath2);
        }
        if (!ObjectUtils.isEmpty(competitionSubmissionDTO.getAttachments3())) {
            String imagePath3 = FileUtils.saveMultipartFile(competitionSubmissionDTO.getAttachments3(),
                    FileUtils.staticPath + RESOURCE_PATH_PREFIX + ValidateCodeUtils.generateCode(4));
            competitionSubmissionDO.setAttachments3(imagePath3);
        }
        competitionSubmissionDAO.updateById(competitionSubmissionDO);
        CompetitionSubmissionDO competitionSubmissionDO1 = competitionSubmissionDAO.selectById(competitionSubmissionDTO.getId());
        CompetitionDO competitionDO = competitionDAO.selectByCompetitionId(competitionSubmissionDO1.getCompetitionId());
        if (competitionSubmissionDTO.getState().equals("赛题作品成功")) {
            MessageDO messageDO = new MessageDO();
            messageDO.setType(1);
            messageDO.setTitle("赛题提交消息");
            messageDO.setContent("您好!您的" + competitionDO.getTitle() + "赛题提交消息审核成功!");
            messageDO.setUsername(competitionSubmissionDTO.getUsername());
            try{
                MessageUtils.sendMessage(competitionSubmissionDTO.getUsername(), sendMessageConfig.getQuestionSuccess());
            }catch (Exception e){
                SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                smsErrLogDO.setPhone(competitionSubmissionDTO.getUsername());
                smsErrLogDO.setType("赛题提交审核成功");
                smsErrLogDAO.insert(smsErrLogDO);
            }


        }
        if (competitionSubmissionDTO.getState().equals("赛题作品失败")) {
            MessageDO messageDO = new MessageDO();
            messageDO.setType(1);
            messageDO.setTitle("赛题提交消息");
            messageDO.setContent("您好!您的" + competitionSubmissionDTO.getUsername() + "赛题提交消息审核失败!");
            messageDO.setUsername(competitionSubmissionDTO.getUsername());
            try{
                MessageUtils.sendMessage(competitionSubmissionDTO.getUsername(), sendMessageConfig.getQuestionFailed());
            }catch (Exception e){
                SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                smsErrLogDO.setPhone(competitionSubmissionDTO.getUsername());
                smsErrLogDO.setType("赛题提交审核失败");
                smsErrLogDAO.insert(smsErrLogDO);
            }

        }
        return Result.success();
    }

    public Result showCompetitionState(HttpServletRequest request) {
        String username = JwtUtils.getUsername(request);
        List<UserCompetitionRelationShipDO> userCompetitionRelationShipDOS = userCompetitionRelationShipDAO.selectByUsername(username);
        return Result.success(userCompetitionRelationShipDOS);
    }

    public Result showUserCompetition(HttpServletRequest request, Integer competitionId) {
        String username = JwtUtils.getUsername(request);
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectIsApplication(username, competitionId);
        if (!CollectionUtils.isEmpty(applicationV2DOList)) {
            return Result.success(applicationV2DOList.get(0));
        }
        return Result.success();
    }

    public Result updateAvatar(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        if (userDTO.getIsShow() == 1) {
            userDO.setAvatar(userDTO.getHeadshot());
            userDAO.updateById(userDO);
        }
        userDAO.updateById(userDO);
        return Result.success("修改头像成功");
    }

    public Result addPraise(DemandDTO demandDTO) {
        List<String> praiseUser = demandDTO.getPraiseUser();
        DemandDO demandDO = new DemandDO();
        if (demandDTO.getIsAdd() == 1) {
            if (praiseUser == null) {
                List<String> praiseUsers = new ArrayList<String>();
                praiseUsers.add(demandDTO.getUsername());
                demandDTO.setPraiseUser(praiseUsers);
                demandDTO.setPraise(demandDTO.getPraise() + 1);
                BeanUtils.copyProperties(demandDTO, demandDO);
                demandDO.setUsername(null);
                demandDO.setIsRead(0);
                demandDAO.updateById(demandDO);
                return Result.success(demandDO.getPraise());
            }
            praiseUser.add(demandDTO.getUsername());
            demandDTO.setPraiseUser(praiseUser);
            demandDTO.setPraise(demandDTO.getPraise() + 1);
            BeanUtils.copyProperties(demandDTO, demandDO);
            demandDO.setUsername(null);
            demandDAO.updateById(demandDO);
            return Result.success(demandDO.getPraise());
        } else {
            praiseUser.remove(demandDTO.getUsername());
            demandDTO.setPraiseUser(praiseUser);
            demandDTO.setPraise(demandDTO.getPraise() - 1);
            BeanUtils.copyProperties(demandDTO, demandDO);
            demandDO.setUsername(null);
            demandDAO.updateById(demandDO);
            return Result.success(demandDO.getPraise());
        }
    }

    public Result addCollection(DemandDTO demandDTO) {
        List<String> collectionUser = demandDTO.getCollectionUser();
        DemandDO demandDO = new DemandDO();
        if (demandDTO.getIsCollection() == 1) {
            if (collectionUser == null) {
                List<String> collectionUsers = new ArrayList<String>();
                collectionUsers.add(demandDTO.getUsername());
                demandDTO.setCollectionUser(collectionUsers);
                demandDTO.setCollection(demandDTO.getCollection() + 1);
                BeanUtils.copyProperties(demandDTO, demandDO);
                demandDO.setUsername(null);
                demandDAO.updateById(demandDO);
                return Result.success(demandDO.getPraise());
            }
            collectionUser.add(demandDTO.getUsername());
            demandDTO.setCollectionUser(collectionUser);
            demandDTO.setCollection(demandDTO.getCollection() + 1);
            BeanUtils.copyProperties(demandDTO, demandDO);
            demandDO.setUsername(null);
            demandDAO.updateById(demandDO);
            return Result.success(demandDO.getCollection());
        } else {
            collectionUser.remove(demandDTO.getUsername());
            demandDTO.setCollectionUser(collectionUser);
            demandDTO.setCollection(demandDTO.getCollection() - 1);
            BeanUtils.copyProperties(demandDTO, demandDO);
            demandDO.setUsername(null);
            demandDAO.updateById(demandDO);
            return Result.success(demandDO.getCollection());
        }
    }

    public Result showOtherProduct(Integer id, String username) {
        List<DemandDO> demandDOS = demandDAO.selectByUserName(username);
        List<DemandDO> collect = demandDOS.stream().filter(item -> !item.getId().equals(id) && item.getIsShow().equals(1)).collect(Collectors.toList());

        return Result.success(collect);
    }

    public Result showPraise(String username) {
        List<DemandPraise> demandPraises = new ArrayList<>();
        List<DemandDO> demandDOS = demandDAO.selectByUserName(username);
        if (!CollectionUtils.isEmpty(demandDOS)) {
            for (int i = 0; i < demandDOS.size(); i++) {
                //获取产品名
                if (!CollectionUtils.isEmpty(demandDOS.get(i).getPraiseUser())) {
                    for (int j = 0; j < demandDOS.get(i).getPraiseUser().size(); j++) {
                        DemandPraise demandPraise = new DemandPraise();
                        demandPraise.setDemandName(demandDOS.get(i).getDemandName());
                        UserDO userDO = userDAO.selectByUsername(demandDOS.get(i).getPraiseUser().get(j));
                        String avatar = userDO.getAvatar();
                        demandPraise.setAvatar(avatar);
                        demandPraise.setUserPraise(userDO.getNickname());
                        demandPraises.add(demandPraise);
                    }
                }
            }
        }
        List<DemandPraise> collect = demandPraises.stream().filter(item -> !item.getUserPraise().equals(username)).collect(Collectors.toList());

        return Result.success(collect);

    }

    public Result showCollection(String username) {
        List<DemandCollection> demandCollections = new ArrayList<>();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        if (!CollectionUtils.isEmpty(demandDOS)) {
            for (int i = 0; i < demandDOS.size(); i++) {
                //获取产品名
                if (!CollectionUtils.isEmpty(demandDOS.get(i).getCollectionUser())&&demandDOS.get(i).getCollectionUser().contains(username)) {
                        DemandCollection demandCollection = new DemandCollection();
                        demandCollection.setId(demandDOS.get(i).getId());
                        demandCollection.setDemandName(demandDOS.get(i).getDemandName());
                        demandCollection.setPicture(demandDOS.get(i).getPicture().get(0));;
                        demandCollections.add(demandCollection);
                    }
                }
            }
        return Result.success(demandCollections);
    }

    public Result replacementCertification(Integer id,String username) {
         if(id==0){
             //个人认证
             UserDO userDO = userDAO.selectByUsername(username);
             userDO.setAuthenticationType("个人认证");
             userDAO.updateByUserName(userDO);
             return  Result.success("切换到个人认证成功");
         }else {
             //企业认证
             UserDO userDO = userDAO.selectByUsername(username);
             userDO.setAuthenticationType("企业认证");
             userDAO.updateByUserName(userDO);
             return  Result.success("切换到企业认证成功");
         }
    }

    public Result showAuthentication(String username) {
        UserInfoVO userInfoVO = new UserInfoVO();
        EnterpriseCertificationVO enterpriseCertificationVO = new EnterpriseCertificationVO();
        UserAuthenticationVO userAuthenticationVO = new UserAuthenticationVO();
        UserDO userDO = userDAO.selectByUsername(username);
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(username);
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectByPhoneNumber(username);
           if(userDO.getIsAuthentication()==0&&CollectionUtils.isEmpty(enterpriseCertificationDOS)){
            return  Result.success("暂无认证");
        }
        //企业认证
       else if(userDO.getAuthenticationType().equals("企业认证")&&CollectionUtils.isEmpty(userAuthenticationDOS)){
               BeanUtils.copyProperties(enterpriseCertificationDOS.get(0),enterpriseCertificationVO);
               userInfoVO.setEnterpriseCertificationVO(enterpriseCertificationVO);
               return  Result.success(userInfoVO);
       }
        //个人认证
       else if(userDO.getAuthenticationType().equals("个人认证")&&CollectionUtils.isEmpty(enterpriseCertificationDOS)){
            BeanUtils.copyProperties(userAuthenticationDOS.get(0),userAuthenticationVO);
            userInfoVO.setUserAuthenticationVO(userAuthenticationVO);
            userAuthenticationVO.setEmail(userDO.getEmail());
            userAuthenticationVO.setAvatar(userDO.getAvatar());
            return  Result.success(userInfoVO);
        }
       else if(userDO.getIsAuthentication()==0&&!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
            BeanUtils.copyProperties(enterpriseCertificationDOS.get(0),enterpriseCertificationVO);
            userInfoVO.setEnterpriseCertificationVO(enterpriseCertificationVO);
            return  Result.success(userInfoVO);
        }
        //个人和企业双证认证
        else{
            BeanUtils.copyProperties(enterpriseCertificationDOS.get(0),enterpriseCertificationVO);
            BeanUtils.copyProperties(userAuthenticationDOS.get(0),userAuthenticationVO);
            userInfoVO.setUserAuthenticationVO(userAuthenticationVO);
            userInfoVO.setEnterpriseCertificationVO(enterpriseCertificationVO);
            userAuthenticationVO.setEmail(userDO.getEmail());
            userAuthenticationVO.setAvatar(userDO.getAvatar());
            return  Result.success(userInfoVO);
        }
    }

    public Result AllDeleteRecord() {
        List<DeleteDemandDO> deleteDemandDOS = deleteDemandDAO.selectAll();
        return  Result.success(deleteDemandDOS);
    }

    public Result detailProductAndShow(Integer id) {
        DemandVO demandVO = new DemandVO();
        DemandDO demandDO = demandDAO.selectByIdAndisshow(id);
        if(demandDO==null){
                return  Result.success(ResultCodeEnum.NO_DATA,demandVO);
        }
        if(demandDO.getIsPublic()==1){
            List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDO.getUsername());
            if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
                demandVO.setEnterpriseCertificationDO(enterpriseCertificationDOS.get(0));
            }
        }
        demandVO.setDemandDO(demandDO);
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDO.getUsername());
        if (!CollectionUtils.isEmpty(enterpriseCertificationDOS)) {
            demandVO.setPosters(enterpriseCertificationDOS.get(0).getPosters());
            String poster = "https://nism.ytcata.com:3005/static/resource/3KKb/91f79f13b90165194f338ee291f8471.jpg";
            ArrayList<String> posters = new ArrayList<>();
            posters.add(poster);
            demandVO.setPosters(posters);
        }
        return Result.success(demandVO);
    }

    public Result showAllPraiseUnRead(String username) {
        List<DemandDO> demandDOS = demandDAO.selectByUserName(username);
        return  null;

    }

    public Result userEnroll() {
        PanelVO panelVO = new PanelVO();
        //获取今天的日期
        LocalDate localDate = LocalDate.now();
        ArrayList<UserDO> userMONDAY = new ArrayList<>();
        ArrayList<UserDO> userTUESDAY = new ArrayList<>();
        ArrayList<UserDO> userWEDNESDAY = new ArrayList<>();
        ArrayList<UserDO> userTHURSDAY = new ArrayList<>();
        ArrayList<UserDO> userFRIDAY= new ArrayList<>();
        ArrayList<UserDO> userSATURDAY = new ArrayList<>();
        ArrayList<UserDO> userSUNDAY = new ArrayList<>();
        ArrayList<UserDO> userAllMONDAY = new ArrayList<>();
        ArrayList<UserDO> userAllTUESDAY = new ArrayList<>();
        ArrayList<UserDO> userAllWEDNESDAY = new ArrayList<>();
        ArrayList<UserDO> userAllTHURSDAY = new ArrayList<>();
        ArrayList<UserDO> userAllFRIDAY= new ArrayList<>();
        ArrayList<UserDO> userAllSATURDAY = new ArrayList<>();
        ArrayList<UserDO> userAllSUNDAY = new ArrayList<>();

        LocalDate MONDAY;
          MONDAY = localDate.minusDays(1);
        LocalDate TUESDAY;
        TUESDAY = localDate.minusDays(2);
        LocalDate WEDNESDAY;
        WEDNESDAY = localDate.minusDays(3);
        LocalDate THURSDAY;
        THURSDAY = localDate.minusDays(4);
        LocalDate FRIDAY;
        FRIDAY = localDate.minusDays(5);
        LocalDate SATURDAY;
        SATURDAY = localDate.minusDays(6);
        LocalDate SUNDAY;
        SUNDAY = localDate.minusDays(7);
        List<UserDO> userDOS1 = userDAO.selectAll();
        List<UserDO> userDOS = userDOS1.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        dataUserShow(userDOS, MONDAY, userMONDAY, TUESDAY, userTUESDAY, WEDNESDAY, userWEDNESDAY, THURSDAY, userTHURSDAY, FRIDAY, userFRIDAY, SATURDAY, userSATURDAY, SUNDAY, userSUNDAY);
        dataAllUserShow(userDOS, MONDAY, userAllMONDAY, TUESDAY, userAllTUESDAY, WEDNESDAY, userAllWEDNESDAY, THURSDAY, userAllTHURSDAY, FRIDAY, userAllFRIDAY, SATURDAY, userAllSATURDAY, SUNDAY, userAllSUNDAY);
        ArrayList<String> dimensions = new ArrayList<>();
        dimensions.add("product");
        dimensions.add("总量");
        dimensions.add("增量");
        panelVO.setDimensions(dimensions);
        DateTimeFormatter df = DateTimeFormatter.ofPattern("MM-dd");
        Source source1 = new Source(MONDAY.format(df),userAllMONDAY.size(),userMONDAY.size());
        Source source2 = new Source(TUESDAY.format(df),userAllTUESDAY.size(),userTUESDAY.size());
        Source source3 = new Source(WEDNESDAY.format(df),userAllWEDNESDAY.size(),userWEDNESDAY.size());
        Source source4 = new Source(THURSDAY.format(df),userAllTHURSDAY.size(),userTHURSDAY.size());
        Source source5 = new Source(FRIDAY.format(df),userAllFRIDAY.size(),userFRIDAY.size());
        Source source6 = new Source(SATURDAY.format(df),userAllSATURDAY.size(),userSATURDAY.size());
        Source source7 = new Source(SUNDAY.format(df),userAllSUNDAY.size(),userSUNDAY.size());
        List<Source> list = Arrays.asList(source7, source6, source5, source4, source3, source2, source1);
        panelVO.setSource(list);
        return  Result.success(panelVO);
    }

    private void dataAllUserShow(List<UserDO> userDOS, LocalDate monday, ArrayList<UserDO> userAllMONDAY, LocalDate tuesday, ArrayList<UserDO> userAllTUESDAY, LocalDate wednesday, ArrayList<UserDO> userAllWEDNESDAY, LocalDate thursday, ArrayList<UserDO> userAllTHURSDAY, LocalDate friday, ArrayList<UserDO> userAllFRIDAY, LocalDate saturday, ArrayList<UserDO> userAllSATURDAY, LocalDate sunday, ArrayList<UserDO> userAllSUNDAY) {
        for(int i = 0; i< userDOS.size(); i++){
            Date createTime = userDOS.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(localDateIsBefore(localDate1,monday)){
                userAllMONDAY.add(userDOS.get(i));
            }
            if(localDateIsBefore(localDate1,tuesday)){
                userAllTUESDAY.add(userDOS.get(i));
            }
            if(localDateIsBefore(localDate1,wednesday)){
                userAllWEDNESDAY.add(userDOS.get(i));
            }
            if(localDateIsBefore(localDate1,thursday)){
                userAllTHURSDAY.add(userDOS.get(i));
            }
            if(localDateIsBefore(localDate1,friday)){
                userAllFRIDAY.add(userDOS.get(i));
            }
            if(localDateIsBefore(localDate1,saturday)){
                userAllSATURDAY.add(userDOS.get(i));
            }
            if(localDateIsBefore(localDate1,sunday)){
                userAllSUNDAY.add(userDOS.get(i));
            }
        }
    }

    /**
    * 比较第一个日期是否或者等于小于第二个日期
    * @param firstDate 第一个日期
    * @param secondDate 第二个日期
    * @return true-小于;false-大于
    */
    public boolean localDateIsBefore(LocalDate firstDate, LocalDate secondDate) {
        return firstDate.isBefore(secondDate)||firstDate.isEqual(secondDate);
    }

    private static void dataUserShow(List<UserDO> userDOS, LocalDate MONDAY, ArrayList<UserDO> userMONDAY, LocalDate TUESDAY, ArrayList<UserDO> userTUESDAY, LocalDate WEDNESDAY, ArrayList<UserDO> userWEDNESDAY, LocalDate THURSDAY, ArrayList<UserDO> userTHURSDAY, LocalDate FRIDAY, ArrayList<UserDO> userFRIDAY, LocalDate SATURDAY, ArrayList<UserDO> userSATURDAY, LocalDate SUNDAY, ArrayList<UserDO> userSUNDAY) {
        for(int i = 0; i< userDOS.size(); i++){
            Date createTime = userDOS.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(MONDAY.isEqual(localDate1)){
                userMONDAY.add(userDOS.get(i));
            }
            else if(TUESDAY.isEqual(localDate1)){
                userTUESDAY.add(userDOS.get(i));
            }
            else if(WEDNESDAY.isEqual(localDate1)){
                userWEDNESDAY.add(userDOS.get(i));
            }
            else if(THURSDAY.isEqual(localDate1)){
                userTHURSDAY.add(userDOS.get(i));
            }
            else if(FRIDAY.isEqual(localDate1)){
                userFRIDAY.add(userDOS.get(i));
            }
            else if(SATURDAY.isEqual(localDate1)){
                userSATURDAY.add(userDOS.get(i));
            }
            else if(SUNDAY.isEqual(localDate1)){
                userSUNDAY.add(userDOS.get(i));
            }
        }
    }
    private  void dataUserAuthenticationShow(List<UserAuthenticationDO> userAuthenticationDOS, LocalDate MONDAY, ArrayList<UserAuthenticationDO> userMONDAY, LocalDate TUESDAY, ArrayList<UserAuthenticationDO> userTUESDAY, LocalDate WEDNESDAY, ArrayList<UserAuthenticationDO> userWEDNESDAY, LocalDate THURSDAY, ArrayList<UserAuthenticationDO> userTHURSDAY, LocalDate FRIDAY, ArrayList<UserAuthenticationDO> userFRIDAY, LocalDate SATURDAY, ArrayList<UserAuthenticationDO> userSATURDAY, LocalDate SUNDAY, ArrayList<UserAuthenticationDO> userSUNDAY) {
        for(int i = 0; i< userAuthenticationDOS.size(); i++){
            Date createTime = userAuthenticationDOS.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(localDateIsBefore(localDate1,MONDAY)){
                userMONDAY.add(userAuthenticationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,TUESDAY)){
                userTUESDAY.add(userAuthenticationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,WEDNESDAY)){
                userWEDNESDAY.add(userAuthenticationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,THURSDAY)){
                userTHURSDAY.add(userAuthenticationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,FRIDAY)){
                userFRIDAY.add(userAuthenticationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,SATURDAY)){
                userSATURDAY.add(userAuthenticationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,SUNDAY)){
                userSUNDAY.add(userAuthenticationDOS.get(i));
            }
        }
    }

    public Result authenticationData() {
        PanelVO1 panelVO = new PanelVO1();
        LocalDate localDate = LocalDate.now();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationMONDAY = new ArrayList<>();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationTUESDAY = new ArrayList<>();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationWEDNESDAY = new ArrayList<>();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationTHURSDAY = new ArrayList<>();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationFRIDAY= new ArrayList<>();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationSATURDAY = new ArrayList<>();
        ArrayList<EnterpriseCertificationDO> enterpriseCertificationSUNDAY = new ArrayList<>();
        ArrayList<UserAuthenticationDO> userMONDAY = new ArrayList<>();
        ArrayList<UserAuthenticationDO> userTUESDAY = new ArrayList<>();
        ArrayList<UserAuthenticationDO> userWEDNESDAY = new ArrayList<>();
        ArrayList<UserAuthenticationDO> userTHURSDAY = new ArrayList<>();
        ArrayList<UserAuthenticationDO> userFRIDAY= new ArrayList<>();
        ArrayList<UserAuthenticationDO> userSATURDAY = new ArrayList<>();
        ArrayList<UserAuthenticationDO> userSUNDAY = new ArrayList<>();
        LocalDate MONDAY;
        MONDAY = localDate.minusDays(1);
        LocalDate TUESDAY;
        TUESDAY = localDate.minusDays(2);
        LocalDate WEDNESDAY;
        WEDNESDAY = localDate.minusDays(3);
        LocalDate THURSDAY;
        THURSDAY = localDate.minusDays(4);
        LocalDate FRIDAY;
        FRIDAY = localDate.minusDays(5);
        LocalDate SATURDAY;
        SATURDAY = localDate.minusDays(6);
        LocalDate SUNDAY;
        SUNDAY = localDate.minusDays(7);
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(1)).collect(Collectors.toList());
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        dataShow(collect,
                MONDAY,
                enterpriseCertificationMONDAY,
                TUESDAY,
                enterpriseCertificationTUESDAY,
                WEDNESDAY,
                enterpriseCertificationWEDNESDAY,
                THURSDAY,
                enterpriseCertificationTHURSDAY,
                FRIDAY,
                enterpriseCertificationFRIDAY,
                SATURDAY,
                enterpriseCertificationSATURDAY,
                SUNDAY,
                enterpriseCertificationSUNDAY);
        dataUserAuthenticationShow(userAuthenticationDOS,
                MONDAY,
                userMONDAY,
                TUESDAY,
                userTUESDAY,
                WEDNESDAY,
                userWEDNESDAY,
                THURSDAY,
                userTHURSDAY,
                FRIDAY,
                userFRIDAY,
                SATURDAY,
                userSATURDAY,
                SUNDAY,
                userSUNDAY);
        ArrayList<String> dimensions = new ArrayList<>();
        dimensions.add("product");
        dimensions.add("企业");
        dimensions.add("个人");
        panelVO.setDimensions(dimensions);
        DateTimeFormatter df = DateTimeFormatter.ofPattern("MM-dd");
        Source1 source1 = new Source1(MONDAY.format(df),enterpriseCertificationMONDAY.size(),userMONDAY.size());
        Source1 source2 = new Source1(TUESDAY.format(df),enterpriseCertificationTUESDAY.size(),userTUESDAY.size());
        Source1 source3 = new Source1(WEDNESDAY.format(df),enterpriseCertificationWEDNESDAY.size(),userWEDNESDAY.size());
        Source1 source4 = new Source1(THURSDAY.format(df),enterpriseCertificationTHURSDAY.size(),userTHURSDAY.size());
        Source1 source5 = new Source1(FRIDAY.format(df),enterpriseCertificationFRIDAY.size(),userFRIDAY.size());
        Source1 source6 = new Source1(SATURDAY.format(df),enterpriseCertificationSATURDAY.size(),userSATURDAY.size());
        Source1 source7 = new Source1(SUNDAY.format(df),enterpriseCertificationSUNDAY.size(),userSUNDAY.size());
        List<Source1> list = Arrays.asList(source7, source6, source5, source4, source3, source2, source1);
        panelVO.setSource(list);
        return  Result.success(panelVO);
    }

    private void dataShow(List<EnterpriseCertificationDO> enterpriseCertificationDOS, LocalDate MONDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationMONDAY, LocalDate TUESDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationTUESDAY, LocalDate WEDNESDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationWEDNESDAY, LocalDate THURSDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationTHURSDAY, LocalDate FRIDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationFRIDAY, LocalDate SATURDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationSATURDAY, LocalDate SUNDAY, ArrayList<EnterpriseCertificationDO> enterpriseCertificationSUNDAY) {
        for(int i = 0; i< enterpriseCertificationDOS.size(); i++){
            Date createTime = enterpriseCertificationDOS.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(localDateIsBefore(localDate1,MONDAY)){
                enterpriseCertificationMONDAY.add(enterpriseCertificationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,THURSDAY)){
                enterpriseCertificationTUESDAY.add(enterpriseCertificationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,WEDNESDAY)){
                enterpriseCertificationWEDNESDAY.add(enterpriseCertificationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,THURSDAY)){
                enterpriseCertificationTHURSDAY.add(enterpriseCertificationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,FRIDAY)){
                enterpriseCertificationFRIDAY.add(enterpriseCertificationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,SATURDAY)){
                enterpriseCertificationSATURDAY.add(enterpriseCertificationDOS.get(i));
            }
            if(localDateIsBefore(localDate1,SUNDAY)){
                enterpriseCertificationSUNDAY.add(enterpriseCertificationDOS.get(i));
            }
        }
    }

    public Result questionsRegistrationData() {
        PanelVO3 panelVO = new PanelVO3();
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectAll();
        ArrayList<CompetitionDO> artificialIntelligence = new ArrayList<>();
        ArrayList<CompetitionDO> bigData = new ArrayList<>();
        ArrayList<CompetitionDO> mobileApp = new ArrayList<>();
        ArrayList<CompetitionDO> robot = new ArrayList<>();
        ArrayList<CompetitionDO> other = new ArrayList<>();
        for(int i=0;i<applicationV2DOList.size();i++){
            CompetitionDO competitionDO = competitionDAO.selectById(applicationV2DOList.get(i).getCompetitionId());
            if(competitionDO.getType()==1){
                artificialIntelligence.add(competitionDO);
            }else if(competitionDO.getType()==2){
                bigData.add(competitionDO);
            }else if(competitionDO.getType()==3){
                mobileApp.add(competitionDO);
            }else if((competitionDO.getType()==4)){
                robot.add(competitionDO);
            }else {
                other.add(competitionDO);
            }
        }
        ArrayList<String> dimensions = new ArrayList<>();
        dimensions.add("赛题");
        dimensions.add("data1");
        panelVO.setDimensions(dimensions);
        Source3 source1 = new Source3("人工智能",artificialIntelligence.size());
        Source3 source2 = new Source3("大数据",bigData.size());
        Source3 source3 = new Source3("移动应用",mobileApp.size());
        Source3 source4 = new Source3("机器人",robot.size());
        Source3 source5 = new Source3("其他",other.size());
        List<Source3> list = Arrays.asList(source1, source2, source3, source4,source5);
        panelVO.setSource(list);
        return  Result.success(panelVO);
    }

    public Result openMarketData() {
        PanelVO2 panelVO = new PanelVO2();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        ArrayList<DemandDO> artificialIntelligence = new ArrayList<>();
        ArrayList<DemandDO> bigData = new ArrayList<>();
        ArrayList<DemandDO> mobileApp = new ArrayList<>();
        ArrayList<DemandDO> robot = new ArrayList<>();
        ArrayList<DemandDO> other = new ArrayList<>();
        for(int i=0;i<demandDOS.size();i++){
            if(demandDOS.get(i).getCategory().equals("人工智能")){
                artificialIntelligence.add(demandDOS.get(i));
            }else if(demandDOS.get(i).getCategory().equals("大数据")){
                bigData.add(demandDOS.get(i));
            }else if(demandDOS.get(i).getCategory().equals("移动应用")){
                mobileApp.add(demandDOS.get(i));
            }else if((demandDOS.get(i).getCategory().equals("机器人"))){
                robot.add(demandDOS.get(i));
            }else {
                other.add(demandDOS.get(i));
            }
        }
        ArrayList<String> dimensions = new ArrayList<>();
        dimensions.add("name");
        dimensions.add("value");
        panelVO.setDimensions(dimensions);
        Source2 source1 = new Source2("人工智能",artificialIntelligence.size());
        Source2 source2 = new Source2("大数据",bigData.size());
        Source2 source3 = new Source2("移动应用",mobileApp.size());
        Source2 source4 = new Source2("机器人",robot.size());
        Source2 source5 = new Source2("其他",other.size());
        List<Source2> list = Arrays.asList(source1, source2, source3, source4,source5);
        panelVO.setSource(list);
        return  Result.success(panelVO);
    }

    public Result productData() {
        List<List<String>> productDatas=new ArrayList<List<String>>();
        List<DemandDO> demandDOS = demandDAO.selectOrderTime();
        for(int i=0;i<demandDOS.size();i++){
            ArrayList<String> productData = new ArrayList<>();
            String style="<span color='#222222' style='margin-left:5px;font-size:12px;background:#526ead;'>"+demandDOS.get(i).getCategory()+"</span><br><font color='#526ead'>2023-09-10</font>";
            productData.add(demandDOS.get(i).getDemandName());
            productData.add(style);
            List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(demandDOS.get(i).getUsername());
            if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
                productData.add(enterpriseCertificationDOS.get(0).getEntName());
                productData.add(enterpriseCertificationDOS.get(0).getPhoneNumber());
            }
            productDatas.add(productData);
        }
        return Result.success(productDatas);
    }

    public Result userEnrollAllData() {
        List<UserDO> userDOS = userDAO.selectAll();
        return  Result.success(userDOS.size()-1);
    }

    public Result enterpriseAllData() {
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(1)).collect(Collectors.toList());
        return  Result.success(collect.size());
    }

    public Result individualAllDate() {
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        return  Result.success(userAuthenticationDOS.size());
    }

    public Result openMarketAllData(){
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        return  Result.success(collect.size());
    }

    public Result competitionAllDate() {
        return  Result.success(applicationV2DAO.selectAll().size());
    }

    public Result webClicks() {
        List<WebViewDO> webViewDOS = webViewDAO.selectAll();
        if(!CollectionUtils.isEmpty(webViewDOS)){
            WebViewDO webViewDO = webViewDOS.get(0);
            return  Result.success(webViewDO.getWebsiteViews());
        }
    return  Result.success(webViewDOS.get(0).getWebsiteViews());
    }

    public Result addWebClicks() {
        List<WebViewDO> webViewDOS = webViewDAO.selectAll();
        if(!CollectionUtils.isEmpty(webViewDOS)){
            WebViewDO webViewDO = webViewDOS.get(0);
            webViewDO.setWebsiteViews(webViewDO.getWebsiteViews()+1);
            webViewDAO.updateById(webViewDO);
        }
        return Result.success("添加点击量成功");
    }

    public Result showEnterprise(HttpServletRequest request) {
        String username = JwtUtils.getUsername(request);
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByPhoneNumber(username);
        if(!CollectionUtils.isEmpty(enterpriseCertificationDOS)){
            return  Result.success(enterpriseCertificationDOS.get(0));
        }
        return  Result.success(enterpriseCertificationDOS.get(0));
    }

    public Result addBulletins(ProductBulletinsDTO bulletinsDTO) {
        ProductBulletinsDO productBulletinsDO = new ProductBulletinsDO();
        BeanUtils.copyProperties(bulletinsDTO,productBulletinsDO);
        if (bulletinsDTO.getImage() != null) {
                String image = ValidateCodeUtils.generateCode(4);
                    String imagePath = FileUtils.saveMultipartFile2(bulletinsDTO.getImage(), devHttpPrefix+ DEMAND_PICTURE_PATH_PREFIX + image,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
            productBulletinsDO.setImage(imagePath);
        }
        productBulletinsDAO.insert(productBulletinsDO);
        return  Result.success("新增产品公告成功!");
    }

    public Result updateBulletins(ProductBulletinsDTO bulletinsDTO) {
        ProductBulletinsDO productBulletinsDO = new ProductBulletinsDO();
        BeanUtils.copyProperties(bulletinsDTO,productBulletinsDO);
        if (bulletinsDTO.getImage() != null) {
            String image = ValidateCodeUtils.generateCode(4);
            String imagePath = FileUtils.saveMultipartFile2(bulletinsDTO.getImage(), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + image,
                    FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
            productBulletinsDO.setImage(imagePath);
        }
        productBulletinsDAO.updateById(productBulletinsDO);
        return  Result.success("修改产品公告成功!");
    }

    public Result deleteBulletins(Integer id) {
        productBulletinsDAO.deleteById(id);
        return  Result.success("修改产品公告成功!");
    }

    public Result selectAllProductsBulletins(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String name = MapUtils.getString(params, "name");
        Page<ProductBulletinsDO> productBulletinsDOS = productBulletinsDAO.selectByPage(new Page<ProductBulletinsDO>
                (pagination.getPageNum(),pagination.getSize()),name);
        return  Result.success(productBulletinsDOS);
    }

    public Result selectProductsBulletins() {
        List<ProductBulletinsDO> productBulletinsDOS = productBulletinsDAO.selectAll();
        List<ProductBulletinsDO> productBulletinsDO=new ArrayList<ProductBulletinsDO>();
        if(productBulletinsDOS.size()<=10){
            return  Result.success(productBulletinsDOS);
        }
        else {
            for(int i=0;i<productBulletinsDOS.size();i++){
                if(i<=10){
                    productBulletinsDO.add(productBulletinsDOS.get(i));
                }
                if(i>10){
                    break;
                }
            }
            return     Result.success(productBulletinsDO);
        }

    }

    public Result artificialIntelligence() {
        List<List<String>> productDatas=new ArrayList<List<String>>();
        List<ArtificialntelligenceDO> artificialntelligenceDOS = artificialntelligenceDAO.selectAll();
        for(int i=0;i<artificialntelligenceDOS.size();i++) {
            ArrayList<String> productData = new ArrayList<>();
            String style = "<font color='#78a3fe'>" + artificialntelligenceDOS.get(i).getContent() + "</font>";
            productData.add(style);
            productDatas.add(productData);
        }
        return Result.success(productDatas);
    }



    public Result smsRegistration() {

        int number=0;
        HashSet<String> columnSet = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机1.xlsx", 1, 1);
        HashSet<String> columnSet1 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机2.xlsx", 1, 1);
        HashSet<String> columnSet2 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机3.xlsx", 1, 1);
        HashSet<String> columnSet3 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机4.xlsx", 1, 1);
        List<String> ls=new ArrayList(columnSet);
        List<String> ls1=new ArrayList(columnSet1);
        List<String> ls2=new ArrayList(columnSet2);
        List<String> ls3=new ArrayList(columnSet3);

        try{
            ls.add("e-5");

        }catch(Exception e){

        }
        try{
            ls1.add("e-5");

        }catch(Exception e){

        }
        try{
            ls2.add("e-5");

        }catch(Exception e){

        }
        try{
            ls3.add("e-5");

        }catch(Exception e){

        }
        ls.addAll(ls1);
        ls.addAll(ls2);
        ls.addAll(ls3);
        List<UserDO> userDOS = userDAO.selectAll();
        for(UserDO userDO:userDOS) {
            if (ls.contains(userDO.getUsername())) {
                System.out.println(userDO.getUsername());
                number++;
            }
        }
        return  Result.success(number);
    }

    public Result test() {
        List<DemandDO> demandDOS = demandDAO.selectAll();
        for(int i=0;i<demandDOS.size();i++){
             ArrayList<String> strings = new ArrayList<>();
            DemandDO demandDO = demandDOS.get(i);
            List<String> picture = demandDO.getPicture();
             for(int j=0;j<picture.size();j++){
                 String s = picture.get(j);
                 String replace = s.replace("8080", "3035");
                 strings.add(replace);
             }
            demandDO.setPicture(strings);
             System.out.println(demandDO);
            demandDAO.updateById(demandDO);
         }
        return  null;
    }

    public Result deleteProductPicture(DeleteProductsDTO deleteProductsDTO) {
        DemandDO demandDO = demandDAO.selectById(deleteProductsDTO.getId());
        List<String> picture = demandDO.getPicture();
        List<String> pictureLink = deleteProductsDTO.getPictureLink();
        for(int i=0;i<picture.size();i++){
            if(pictureLink.contains(picture.get(i))){
                picture.remove(picture.get(i));
            }
        }
        demandDO.setPicture(picture);
        demandDAO.updateById(demandDO);
        return  Result.success("图片删除成功");
    }

    public Result awaitReviewed() {
        List<List<String>> awaitReviewedDates=new ArrayList<List<String>>();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getIsShow().equals(0)).collect(Collectors.toList());
        for(int i=0;i<collect.size();i++){
            ArrayList<String> awaitReviewedDate = new ArrayList<>();
            awaitReviewedDate.add(collect.get(i).getDemandName());
            awaitReviewedDate.add(collect.get(i).getCompanyName());
            awaitReviewedDates.add(awaitReviewedDate);
        }
        return  Result.success(awaitReviewedDates);
    }

    public Result authenticationReviewed() {
        List<List<String>> authenticationRevieweDatas=new ArrayList<List<String>>();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(0)).collect(Collectors.toList());
        for(int i=0;i<collect.size();i++){
            ArrayList<String> authenticationRevieweData = new ArrayList<>();
            authenticationRevieweData.add(collect.get(i).getEntName());
            authenticationRevieweData.add("企业");
            authenticationRevieweDatas.add(authenticationRevieweData);
        }
        return  Result.success(authenticationRevieweDatas);
    }

    public Result userAreaMapData() {
        List<String> point=new ArrayList<>();
         List<String> line=new ArrayList<>();
        List<AreaVO> map=new ArrayList<>();
        List<PiecesVO> pieces=new ArrayList<>();
        AreaMapDataVO areaMapDataVO = new AreaMapDataVO();
        areaMapDataVO.setPoint(point);
        areaMapDataVO.setLine(line);
        List<UserDO> userDOS = userDAO.selectAll();
        List<UserDO> collect2 = userDOS.stream().filter(item -> item.getIsEnterpriseCertification().equals(1)).collect(Collectors.toList());
        List<String> collect = collect2.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        collect.removeAll(Collections.singleton(null));
        Map<String, Integer> maps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect)){
            for (String k: collect) {
                Integer count = maps.get(k);
                maps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> valueList = maps.keySet().stream().collect(Collectors.toList());
        List<Integer> collect1 = maps.values().stream().collect(Collectors.toList());
        for(int i=0;i<valueList.size();i++){
            AreaVO areaVO = new AreaVO(valueList.get(i),collect1.get(i));
            map.add(areaVO);
        }
        areaMapDataVO.setMap(map);


        PiecesVO piecesVO = new PiecesVO(500,null, ">500");
        PiecesVO piecesVO1 = new PiecesVO(300,400, "300-400");
        PiecesVO piecesVO2 = new PiecesVO(100,299, "100-299");
        PiecesVO piecesVO3 = new PiecesVO(50,199, "49-199");
        PiecesVO piecesVO4 = new PiecesVO(10,49, "10-49");
        PiecesVO piecesVO5 = new PiecesVO(null,9, "<9");
        pieces = Arrays.asList(piecesVO, piecesVO1, piecesVO2, piecesVO3, piecesVO4, piecesVO5);
        areaMapDataVO.setPieces(pieces);
        return  Result.success(areaMapDataVO);

    }

    public Result awaitReviewedDate() {
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getIsShow().equals(0)).collect(Collectors.toList());
        return  Result.success("产品待审核("+collect.size()+")");
    }

    public Result authenticationReviewedDate() {
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(0)).collect(Collectors.toList());
        return  Result.success("实名待审核("+collect.size()+")");
    }


    public Result addShare(DemandDTO demandDTO) {
        DemandDO demandDO = demandDAO.selectById(demandDTO.getId());
        demandDO.setShareNumbers(demandDTO.getShareNumbers()+1);
        List<String> shareUser = demandDO.getShareUser();
        if(!shareUser.contains(demandDTO.getUsername())){
            shareUser.add(demandDTO.getUsername());
        }
        demandDO.setShareUser(shareUser);
        demandDAO.updateById(demandDO);
        return  Result.success(demandDO);
    }

    public Result getBooks(HttpServletRequest request) {
        String username = JwtUtils.getUsername(request);
        UserDO userDO = userDAO.selectByUsername(username);
        List<String> meetings = userDO.getMeetings();
        ArrayList<MeetingDO> meetingDOS = new ArrayList<>();
        if(!CollectionUtils.isEmpty(meetings)){
            for(String meeting:meetings){
                MeetingDO meetingDO = meetingDAO.selectById(Integer.parseInt(meeting));
                meetingDOS.add(meetingDO);
            }
        }
        return  Result.success(meetingDOS);

    }


    public Result userAreaMapData1() {

        List<AreaVO> map=new ArrayList<>();
        List<UserDO> userDOS = userDAO.selectAll();
        List<UserDO> collect2 = userDOS.stream().filter(item -> item.getIsEnterpriseCertification().equals(1)).collect(Collectors.toList());
        List<String> collect = collect2.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        collect.removeAll(Collections.singleton(null));
        Map<String, Integer> maps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect)){
            for (String k: collect) {
                Integer count = maps.get(k);
                maps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> valueList = maps.keySet().stream().collect(Collectors.toList());
        List<Integer> collect1 = maps.values().stream().collect(Collectors.toList());
        for(int i=0;i<valueList.size();i++){
            AreaVO areaVO = new AreaVO(valueList.get(i),collect1.get(i));
            map.add(areaVO);
        }
        return  Result.success(map);

    }

    public Result userEnrollDetailData() {
        List<UserDO> userDOS = userDAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        List<UserDO> collect = userDOS.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        for(int i=0;i<collect.size();i++){
            ArrayList<Object> arrayList = new ArrayList<>();
            if(collect.get(i).getEntName()!=null&&!collect.get(i).getEntName().equals("")){
                arrayList.add(collect.get(i).getEntName());
            }else if(collect.get(i).getIndividual()!=null&&!collect.get(i).getIndividual().equals("")){
                arrayList.add(collect.get(0).getIndustry());
            }else {
                arrayList.add(collect.get(0).getNickname());
            }
            arrayList.add(phoneSecrecy(collect.get(i).getUsername()));
            LocalDate localDate1= collect.get(i).getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            arrayList.add(localDate1);
            listArrayList.add(arrayList);

        }
        return  Result.success(listArrayList);

    }

    public Result entDetail() {
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(1)).collect(Collectors.toList());
        for(int i=0;i<collect.size();i++){
            ArrayList<Object> arrayList = new ArrayList<>();

            arrayList.add(collect.get(i).getEntName());
            arrayList.add(phoneSecrecy(collect.get(i).getPhoneNumber()));
            LocalDate localDate1= collect.get(i).getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            arrayList.add(localDate1);
            listArrayList.add(arrayList);

        }
        return  Result.success(listArrayList);
    }

    public Result individualDetail() {
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        for(int i=0;i<userAuthenticationDOS.size();i++){
            ArrayList<Object> arrayList = new ArrayList<>();

            arrayList.add(userAuthenticationDOS.get(i).getName());
            arrayList.add(phoneSecrecy(userAuthenticationDOS.get(i).getPhone()));
            LocalDate localDate1= userAuthenticationDOS.get(i).getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            arrayList.add(localDate1);
            listArrayList.add(arrayList);
        }
        return  Result.success(listArrayList);
    }

    public Result ProductDetail() {
        List<DemandDO> demandDOS = demandDAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        for(int i=0;i<demandDOS.size();i++){
            ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(demandDOS.get(i).getCompanyName());
            arrayList.add(demandDOS.get(i).getDemandName());
            arrayList.add(phoneSecrecy(demandDOS.get(i).getUsername()));
            listArrayList.add(arrayList);
        }
        return  Result.success(listArrayList);
    }

    public Result questionsDetail() {
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        for(int i=0;i<applicationV2DOList.size();i++){
            ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(applicationV2DOList.get(i).getCompetitionName());
            arrayList.add(applicationV2DOList.get(i).getBizName());
             arrayList.add(phoneSecrecy(applicationV2DOList.get(i).getUsername()));
            listArrayList.add(arrayList);
        }
        return  Result.success(listArrayList);
    }

    public Result smsDetail() {
        int number=0;
        HashSet<String> columnSet = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机1.xlsx", 1, 1);
        HashSet<String> columnSet1 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机2.xlsx", 1, 1);
        HashSet<String> columnSet2 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机3.xlsx", 1, 1);
        HashSet<String> columnSet3 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机4.xlsx", 1, 1);
        List<String> ls=new ArrayList(columnSet);
        List<String> ls1=new ArrayList(columnSet1);
        List<String> ls2=new ArrayList(columnSet2);
        List<String> ls3=new ArrayList(columnSet3);

        try{
            ls.add("e-5");

        }catch(Exception e){
            System.out.println(e.toString());
        }
        try{
            ls1.add("e-5");

        }catch(Exception e){
            System.out.println(e.toString());
        }
        try{
            ls2.add("e-5");

        }catch(Exception e){
            System.out.println(e.toString());
        }
        try{
            ls3.add("e-5");

        }catch(Exception e){
            System.out.println(e.toString());
        }
        ls.addAll(ls1);
        ls.addAll(ls2);
        ls.addAll(ls3);
        List<UserDO> userDOS = userDAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        for(UserDO userDO:userDOS) {
            ArrayList<Object> arrayList = new ArrayList<>();
            if (ls.contains(userDO.getUsername())) {
                if(userDO.getEntName()!=null&&!userDO.getEntName().equals("")){
                    arrayList.add(userDO.getEntName());
                }else if(userDO.getIndividual()!=null&&!userDO.getIndividual().equals("")){
                    arrayList.add(userDO.getIndividual());
                }else {
                    arrayList.add(userDO.getNickname());
                }
                arrayList.add(phoneSecrecy(userDO.getUsername()));
                LocalDate localDate1= userDO.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                arrayList.add(localDate1);
                listArrayList.add(arrayList);
                }

            }
        return  Result.success(listArrayList);
    }

    public Result productDetailByProvince(String province) {
        List<DemandDO> demandDOS = demandDAO.selectByProvince(province);
        List<DemandLookDO> demandLookDOS = demandLookDAO.selectAll();
        if(!CollectionUtils.isEmpty(demandLookDOS)){
            for(DemandLookDO demandLookDO:demandLookDOS){
                demandLookDAO.deleteById(demandLookDO.getId());
            }
        }
        for(DemandDO demandDO:demandDOS){
            DemandLookDO demandLookDO = new DemandLookDO();
            BeanUtils.copyProperties(demandDO,demandLookDO);
            demandLookDAO.insert(demandLookDO);
        }
        return  Result.success();
    }


    public Result productDetailShow() {
        List<DemandLookDO> demandLookDOS = demandLookDAO.selectAll();
        ArrayList<List<Object>> listArrayList = new ArrayList<>();
        for(int i=0;i<demandLookDOS.size();i++){
            ArrayList<Object> arrayList = new ArrayList<>();
            arrayList.add(demandLookDOS.get(i).getCompanyName());
            arrayList.add(demandLookDOS.get(i).getDemandName());
            arrayList.add(phoneSecrecy(demandLookDOS.get(i).getUsername()));
            listArrayList.add(arrayList);
        }
        return  Result.success(listArrayList);
    }
    public CoreDataVO coreData() {
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectAll();
        List<UserDO> userDOS = userDAO.selectAll();
        List<UserDO> collect = userDOS.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect1 = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        DataVO dataVO = new DataVO(enterpriseCertificationDOS.size(),applicationV2DOList.size(),collect.size(),collect1.size());
        coreDataVO.setData(dataVO);
        return  coreDataVO;
    }

    public CoreDataVO dataOverview() {
        List<UserDO> userDOS = userDAO.selectAll();
        List<UserDO> collect = userDOS.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect1 = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectAll();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        List<UsersOnlineDO> usersOnlineDOS = usersOnlineDAO.selectAll();
        Integer smsNumber = smsNumber();
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        DataVO1 dataVO1 = new DataVO1(collect.size(), collect1.size(), applicationV2DOList.size(), enterpriseCertificationDOS.size(),
                userAuthenticationDOS.size(), usersOnlineDOS.size(), smsNumber);
        coreDataVO.setData(dataVO1);
        return coreDataVO;
    }

    public  Integer smsNumber(){
        int number=0;
        HashSet<String> columnSet = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机1.xlsx", 1, 1);
        HashSet<String> columnSet1 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机2.xlsx", 1, 1);
        HashSet<String> columnSet2 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机3.xlsx", 1, 1);
        HashSet<String> columnSet3 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/phone/分批手机4.xlsx", 1, 1);
//        HashSet<String> columnSet = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/1313/分批手机1.xlsx", 1, 1);
//        HashSet<String> columnSet1 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/31313/分批手机4.xlsx", 1, 1);
//        HashSet<String> columnSet2 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/1313/分批手机2.xlsx", 1, 1);
//        HashSet<String> columnSet3 = ExcelUtil.getColumnSet("/home/ubuntu/java_project/static/resource/131313/分批手机3.xlsx", 1, 1);
        List<String> ls=new ArrayList(columnSet);
        List<String> ls1=new ArrayList(columnSet1);
        List<String> ls2=new ArrayList(columnSet2);
        List<String> ls3=new ArrayList(columnSet3);

        try{
            ls.add("e-5");

        }catch(Exception e){

        }
        try{
            ls1.add("e-5");

        }catch(Exception e){

        }
        try{
            ls2.add("e-5");

        }catch(Exception e){

        }
        try{
            ls3.add("e-5");

        }catch(Exception e){

        }
        ls.addAll(ls1);
        ls.addAll(ls2);
        ls.addAll(ls3);
        List<UserDO> userDOS = userDAO.selectAll();
        for(UserDO userDO:userDOS) {
            if (ls.contains(userDO.getUsername())) {
                System.out.println(userDO.getUsername());
                number++;
            }
        }
        return  number;
    }

    public CoreDataVO realNamePendingReview() {
        CoreDataVO coreDataVO = new CoreDataVO();
        listDataVO2 listDataVO2 = new listDataVO2();
        List<DataVO2> dataVO2s = new ArrayList<>();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(0)).collect(Collectors.toList());
        for(int i=0;i<collect.size();i++){
            LocalDate localDate1= collect.get(i).getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            DataVO2 dataVO2 = new DataVO2(collect.get(i).getMapAddress(),localDate1,0,collect.get(i).getEntName());
            dataVO2s.add(dataVO2);
        }
        listDataVO2.setList(dataVO2s);
        coreDataVO.setSuccess(true);
        coreDataVO.setData(listDataVO2);
        return  coreDataVO;
    }

    public CoreDataVO productMap() {
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        listDataVO3 listDataVO3 = new listDataVO3();
        List<DataVO3> dataVO3s = new ArrayList<>();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect2 = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<String> collect = collect2.stream().map(item -> item.getCompanyAddress()).collect(Collectors.toList());
        collect.removeAll(Collections.singleton(null));
        Map<String, Integer> maps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect)){
            for (String k: collect) {
                Integer count = maps.get(k);
                maps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> valueList = maps.keySet().stream().collect(Collectors.toList());
        List<Integer> collect1 = maps.values().stream().collect(Collectors.toList());
        for(int i=0;i<valueList.size();i++){
            DataVO3 dataVO3 = new DataVO3(valueList.get(i),collect1.get(i));
            dataVO3s.add(dataVO3);
        }
        listDataVO3.setDataList(dataVO3s);
        listDataVO3.setRegionCode("china");
        coreDataVO.setData(listDataVO3);
        return  coreDataVO;
    }

    public CoreDataVO showProduct() {
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        DataVO4 dataVO4 = new DataVO4();
        List<String> category = new ArrayList<>();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(1) || item.getCertificationResults().equals(-1)).collect(Collectors.toList());
        List<String> collect3= collect.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        collect3.removeAll(Collections.singleton(null));
        Map<String, Integer> maps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect3)){
            for (String k: collect3) {
                Integer count = maps.get(k);
                maps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        category= maps.keySet().stream().collect(Collectors.toList());
        List<Integer> allNumber = maps.values().stream().collect(Collectors.toList());
        List<Integer> barData = new ArrayList<>();
        List<Integer> lineData =new ArrayList<>();
        List<Integer> rateData =new ArrayList<>();
        for(int i=0;i<category.size();i++){
            barData.add(0);
            lineData.add(0);
            rateData.add(0);
        }


        List<EnterpriseCertificationDO> success = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(1)).collect(Collectors.toList());
        List<String> success1 = success.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        Map<String, Integer> successMaps = new HashMap<>();
        if(!CollectionUtils.isEmpty(success1)){
            for (String k: success1) {
                Integer count = successMaps.get(k);
                successMaps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> successAddress = successMaps.keySet().stream().collect(Collectors.toList());
        List<Integer> successNumber = successMaps.values().stream().collect(Collectors.toList());
        List<EnterpriseCertificationDO> fail = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(-1)).collect(Collectors.toList());
        List<String> fail1 = fail.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        Map<String, Integer> failMaps = new HashMap<>();
        if(!CollectionUtils.isEmpty(fail1)){
            for (String k: fail1) {
                Integer count = failMaps.get(k);
                failMaps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> failAddress = failMaps.keySet().stream().collect(Collectors.toList());
        List<Integer> failNumber = failMaps.values().stream().collect(Collectors.toList());
        for(int i=0;i<category.size();i++){
            int isValue=0;
            for(int j=0;j<successAddress.size();j++){
                if(isValue==0){
                    barData.set(i,0);
                }else {
                    continue;
                }
                if(category.get(i).equals(successAddress.get(j))){
                    barData.set(i,successNumber.get(j));
                    isValue=1;
                }
            }
        }
        for(int i=0;i<category.size();i++){
            int isValue=0;
            for(int j=0;j<failAddress.size();j++){
                if(isValue==0){
                    lineData.set(i,0);
                }else {
                    continue;
                }
                if(category.get(i).equals(failAddress.get(j))){
                    lineData.set(i,failNumber.get(j));
                    isValue=1;
                }
            }
        }
        for(int i=0;i<category.size();i++) {
            Double barDataNum = (double)barData.get(i);
            Double allNumberNum = (double) allNumber.get(i);
            Double rate=(barDataNum/allNumberNum)*100;
            rateData.set(i,(int) Math.round(rate));
        }
        dataVO4.setCategory(category);
        dataVO4.setLineData(lineData);
        dataVO4.setBarData(barData);
        dataVO4.setRateData(rateData);
        coreDataVO.setData(dataVO4);
        return  coreDataVO;
    }

    public CoreDataVO userChanges() {
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        //获取今天的日期
        LocalDate localDate = LocalDate.now();
        ArrayList<UserDO> userMONDAY = new ArrayList<>();
        ArrayList<UserDO> userTUESDAY = new ArrayList<>();
        ArrayList<UserDO> userWEDNESDAY = new ArrayList<>();
        ArrayList<UserDO> userTHURSDAY = new ArrayList<>();
        ArrayList<UserDO> userFRIDAY= new ArrayList<>();
        ArrayList<UserDO> userSATURDAY = new ArrayList<>();
        ArrayList<UserDO> userSUNDAY = new ArrayList<>();
        ArrayList<UserDO> userAllMONDAY = new ArrayList<>();
        ArrayList<UserDO> userAllTUESDAY = new ArrayList<>();
        ArrayList<UserDO> userAllWEDNESDAY = new ArrayList<>();
        ArrayList<UserDO> userAllTHURSDAY = new ArrayList<>();
        ArrayList<UserDO> userAllFRIDAY= new ArrayList<>();
        ArrayList<UserDO> userAllSATURDAY = new ArrayList<>();
        ArrayList<UserDO> userAllSUNDAY = new ArrayList<>();

        LocalDate MONDAY;
        MONDAY = localDate.minusDays(1);
        LocalDate TUESDAY;
        TUESDAY = localDate.minusDays(2);
        LocalDate WEDNESDAY;
        WEDNESDAY = localDate.minusDays(3);
        LocalDate THURSDAY;
        THURSDAY = localDate.minusDays(4);
        LocalDate FRIDAY;
        FRIDAY = localDate.minusDays(5);
        LocalDate SATURDAY;
        SATURDAY = localDate.minusDays(6);
        LocalDate SUNDAY;
        SUNDAY = localDate.minusDays(7);
        List<LocalDate> dateList = Arrays.asList(SUNDAY, SATURDAY, FRIDAY, THURSDAY, WEDNESDAY, TUESDAY, MONDAY);

        List<UserDO> userDOS1 = userDAO.selectAll();
        List<UserDO> userDOS = userDOS1.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        dataUserShow(userDOS, MONDAY, userMONDAY, TUESDAY, userTUESDAY, WEDNESDAY, userWEDNESDAY, THURSDAY, userTHURSDAY, FRIDAY, userFRIDAY, SATURDAY, userSATURDAY, SUNDAY, userSUNDAY);
        dataAllUserShow(userDOS, MONDAY, userAllMONDAY, TUESDAY, userAllTUESDAY, WEDNESDAY, userAllWEDNESDAY, THURSDAY, userAllTHURSDAY, FRIDAY, userAllFRIDAY, SATURDAY, userAllSATURDAY, SUNDAY, userAllSUNDAY);
        List<Integer> numList = Arrays.asList(userSUNDAY.size(), userSATURDAY.size(), userFRIDAY.size(), userTHURSDAY.size(), userWEDNESDAY.size(), userTUESDAY.size(), userMONDAY.size());
        List<Integer> numList2 = Arrays.asList(userAllSUNDAY.size(), userAllSATURDAY.size(), userAllFRIDAY.size(), userAllTHURSDAY.size(), userAllWEDNESDAY.size(), userAllTUESDAY.size(), userAllMONDAY.size());
        DataVO5  dataVO5= new DataVO5(dateList,numList,numList2);
        coreDataVO.setData(dataVO5);
        return  coreDataVO;
    }

    public CoreDataVO productSort() {
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        ArrayList<DataVO6> data = new ArrayList<>();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect2 = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<String> collect = collect2.stream().map(item -> item.getCompanyAddress()).collect(Collectors.toList());
        collect.removeAll(Collections.singleton(null));
        Map<String, Integer> maps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect)){
            for (String k: collect) {
                Integer count = maps.get(k);
                maps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        Map<String, Integer> sortMap = MapSortUtil.sortMap(maps);
        List<String> valueList = sortMap.keySet().stream().collect(Collectors.toList());
        List<Integer> collect1 = sortMap.values().stream().collect(Collectors.toList());
        if(valueList.size()>=8){
            for(int i=0;i<8;i++){
                DataVO6 dataVO3 = new DataVO6(collect1.get(i),valueList.get(i));
                data.add(dataVO3);
            }
        }else {
            for(int i=0;i<valueList.size();i++){
                DataVO6 dataVO3 = new DataVO6(collect1.get(i),valueList.get(i));
                data.add(dataVO3);
            }
        }

        coreDataVO.setData(data);
        return  coreDataVO;
    }

    public CoreDataVO productToReviewed() {
        CoreDataVO coreDataVO = new CoreDataVO();
        coreDataVO.setSuccess(true);
        ArrayList<DataVO7> data = new ArrayList<>();
        listDataVO7 listDataVO7 = new listDataVO7();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect2 = demandDOS.stream().filter(item -> item.getIsShow().equals(0)).collect(Collectors.toList());
        for(int i=0;i<collect2.size();i++){
            LocalDate localDate1= collect2.get(i).getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            DataVO7 dataVO7 = new DataVO7(collect2.get(i).getDemandName(),localDate1,collect2.get(i).getSerialNumber(),collect2.get(i).getCompanyAddress());
            data.add(dataVO7);
        }
        listDataVO7.setList(data);
        coreDataVO.setData(listDataVO7);
        return  coreDataVO;
    }

    public Result searchEnterprise(String entName) {
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectByEntName(entName);
        List<String> entNames = enterpriseCertificationDOS.stream().map(item -> item.getEntName()).collect(Collectors.toList());
        return  Result.success(entNames);
    }

    public BasicDataVO roseChart() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<String> xData = Arrays.asList("人工智能", "机器人", "大数据", "智能设备", "通信工程", "其他");
        RoseChartVO roseChartVO = new RoseChartVO();
        List<DataVO6> dataVO6s = new ArrayList<>();
        int AGNumber=0;
        int JQRNumber=0;
        int DSJNumber=0;
        int ZNSBNumber=0;
        int TXNumber=0;
        int QT=0;
        for(int i=0;i<collect.size();i++){
            if(collect.get(i).getCategory().equals("人工智能")){
                AGNumber++;
            }
            if(collect.get(i).getCategory().equals("机器人")){
                JQRNumber++;
            }
            if(collect.get(i).getCategory().equals("大数据")){
                DSJNumber++;
            }
            if(collect.get(i).getCategory().equals("智能设备")){
                ZNSBNumber++;
            }
            if(collect.get(i).getCategory().equals("通信工程")){
                TXNumber++;
            }
            if(collect.get(i).getCategory().equals("其他")){
                QT++;
            }
        }
        DataVO6 dataVO1 = new DataVO6(AGNumber,"人工智能");
        DataVO6 dataVO2 = new DataVO6(JQRNumber,"机器人");
        DataVO6 dataVO3 = new DataVO6(DSJNumber,"大数据");
        DataVO6 dataVO4 = new DataVO6(ZNSBNumber,"智能设备");
        DataVO6 dataVO5 = new DataVO6(TXNumber,"通信工程");
        DataVO6 dataVO6 = new DataVO6(QT,"其他");
        dataVO6s=Arrays.asList(dataVO1,dataVO2,dataVO3,dataVO4,dataVO4,dataVO5,dataVO6);
        roseChartVO.setXData(xData);
        roseChartVO.setSeriesData(dataVO6s);
        basicDataVO.setData(roseChartVO);
        return  basicDataVO;
    }

    public BasicDataVO roseChart1() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<DemandDO> collect1 = demandDOS.stream().filter(item -> item.getIsShow().equals(-1)).collect(Collectors.toList());
        List<DemandDO> collect2 = demandDOS.stream().filter(item -> item.getIsShow().equals(0)).collect(Collectors.toList());
        RoseChartVO1 roseChartVO1 = new RoseChartVO1(collect2.size(),"待通过");
        RoseChartVO1 roseChartVO2 = new RoseChartVO1(demandDOS.size(),"产品总量");
        RoseChartVO1 roseChartVO3 = new RoseChartVO1(collect1.size(),"上架失败");
        RoseChartVO1 roseChartVO4 = new RoseChartVO1(collect.size(),"已通过");
        List<RoseChartVO1> list = Arrays.asList(roseChartVO1, roseChartVO2, roseChartVO3, roseChartVO4);
        basicDataVO.setData(list);
        return  basicDataVO;


    }

    public BasicDataVO basicInformation() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<UserDO> userDOS = userDAO.selectAll();
        List<UserDO> collect = userDOS.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect1 = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectAll();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        Integer smsNumber = smsNumber();
        RoseChartVO1 roseChartVO1 = new RoseChartVO1(collect.size(),"用户注册总量");
        RoseChartVO1 roseChartVO2 = new RoseChartVO1(enterpriseCertificationDOS.size(),"企业实名总量");
        RoseChartVO1 roseChartVO3 = new RoseChartVO1(userAuthenticationDOS.size(),"个人实名总量");
        RoseChartVO1 roseChartVO4 = new RoseChartVO1(applicationV2DOList.size(),"赛题报名总量");
        RoseChartVO1 roseChartVO5 = new RoseChartVO1(collect1.size(),"开放市场总产品总量");
        RoseChartVO1 roseChartVO6 = new RoseChartVO1(smsNumber,"通过短信注册的总量");
        List<RoseChartVO1> list = Arrays.asList(roseChartVO1, roseChartVO2, roseChartVO3, roseChartVO4,roseChartVO5,roseChartVO6);
        basicDataVO.setData(list);
        return  basicDataVO;
    }

    public BasicDataVO productSortV() {
        BasicDataVO basicDataVO = new BasicDataVO();
        ArrayList<DataVO3> data = new ArrayList<>();
        productSortVO productSortVO = new productSortVO();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        List<DemandDO> collect2 = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        List<String> collect = collect2.stream().map(item -> item.getCompanyAddress()).collect(Collectors.toList());
        collect.removeAll(Collections.singleton(null));
        Map<String, Integer> maps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect)){
            for (String k: collect) {
                Integer count = maps.get(k);
                maps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        Map<String, Integer> sortMap = MapSortUtil.sortMap(maps);
        List<String> valueList = sortMap.keySet().stream().collect(Collectors.toList());
        List<Integer> collect1 = sortMap.values().stream().collect(Collectors.toList());
        if(valueList.size()>=8){
            for(int i=0;i<8;i++){
                DataVO3 dataVO3 = new DataVO3(valueList.get(i),collect1.get(i));
                data.add(dataVO3);
            }
        }else {
            for(int i=0;i<valueList.size();i++){
                DataVO3 dataVO3 = new DataVO3(valueList.get(i),collect1.get(i));
                data.add(dataVO3);
            }
        }
        productSortVO.setData(data);
        productSortVO.setCarousel("single");
        productSortVO.setUnit("人");
        basicDataVO.setData(productSortVO);
        return  basicDataVO;
    }

    public BasicDataVO callDay() {
        BasicDataVO basicDataVO = new BasicDataVO();
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("0");
        arrayList.add("50");
        arrayList.add("25%");
        basicDataVO.setData(arrayList);
        return  basicDataVO;
    }

    public BasicDataVO questionsData() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<CompetitionDO> competitionDOList = competitionDAO.selectAll();
        int AGNumber=0;
        int JQRNumber=0;
        int DSJNumber=0;
        int ZNSBNumber=0;
        int TXNumber=0;
        int  QT=0;
        for(int i=0;i<competitionDOList.size();i++){
            if(competitionDOList.get(i).getType()==1){
                AGNumber++;
            }
            if(competitionDOList.get(i).getType()==2){
                JQRNumber++;
            }
            if(competitionDOList.get(i).getType()==3){
                DSJNumber++;
            }
            if(competitionDOList.get(i).getType()==4){
                ZNSBNumber++;
            }
            if(competitionDOList.get(i).getType()==5){
                TXNumber++;
            }
            if(competitionDOList.get(i).getType()==8){
                QT++;
            }
        }
        DataVO3 dataVO1 = new DataVO3("人工智能",AGNumber);
        DataVO3 dataVO2 = new DataVO3("机器人",JQRNumber);
        DataVO3 dataVO3 = new DataVO3("大数据",DSJNumber);
        DataVO3 dataVO4 = new DataVO3("智能设备",ZNSBNumber);
        DataVO3 dataVO5 = new DataVO3("通信工程",TXNumber);
        DataVO3 dataVO6 = new DataVO3("其他",QT);
        ArrayList<DataVO3> dataVO3s = new ArrayList<>();
        dataVO3s.add(dataVO1);
        dataVO3s.add(dataVO2);
        dataVO3s.add(dataVO3);
        dataVO3s.add(dataVO4);
        dataVO3s.add(dataVO5);
        dataVO3s.add(dataVO6);
        DataVO3List dataVO3List = new DataVO3List(dataVO3s, true);
        basicDataVO.setData(dataVO3List);
        return  basicDataVO;
    }

    public BasicDataVO questionsRadar() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<CompetitionDO> competitionDOList = competitionDAO.selectAll();
        int AGNumber=0;
        int JQRNumber=0;
        int DSJNumber=0;
        int ZNSBNumber=0;
        int TXNumber=0;
        int  QT=0;
        for(int i=0;i<competitionDOList.size();i++){
            if(competitionDOList.get(i).getType()==1){
                AGNumber++;
            }
            if(competitionDOList.get(i).getType()==2){
                JQRNumber++;
            }
            if(competitionDOList.get(i).getType()==3){
                DSJNumber++;
            }
            if(competitionDOList.get(i).getType()==4){
                ZNSBNumber++;
            }
            if(competitionDOList.get(i).getType()==5){
                TXNumber++;
            }
            if(competitionDOList.get(i).getType()==8){
                QT++;
            }
        }
        DataVO8 dataVO1= new  DataVO8("人工智能",AGNumber);
        DataVO8 dataVO2 = new DataVO8("机器人",JQRNumber);
        DataVO8 dataVO3 = new DataVO8("大数据",DSJNumber);
        DataVO8 dataVO4 = new DataVO8("智能设备",ZNSBNumber);
        DataVO8 dataVO5 = new DataVO8("通信工程",TXNumber);
        DataVO8 dataVO6 = new DataVO8("其他",QT);
        List<DataVO8> list = Arrays.asList(dataVO1, dataVO2, dataVO3, dataVO4, dataVO5, dataVO6);
        basicDataVO.setData(list);
        return  basicDataVO;
    }

    public BasicDataVO productComparison() {
        String temp="";
        BasicDataVO basicDataVO = new BasicDataVO();
        List<DemandDO> demandDOS = demandDAO.selectAll();
        LocalDate localDate = LocalDate.now();
        LocalDate  yesterday  = localDate.minusDays(1);
        LocalDate  data1  = localDate.minusDays(2);
        LocalDate  data2  = localDate.minusDays(3);
        LocalDate  data3  = localDate.minusDays(4);
        LocalDate  data4  = localDate.minusDays(5);
        LocalDate  data5  = localDate.minusDays(6);
        LocalDate  data6  = localDate.minusDays(7);
        LocalDate  data7  = localDate.minusDays(8);

        int today=0;
        int yesterday1 = 0;
        int data1Num = 0;
        int data2Num=0,data3Num=0,data4Num=0,data5Num=0,data6Num=0,data7Num=0;
        String add="↑";
        String decline="↓";

        List<DemandDO> collect = demandDOS.stream().filter(item -> item.getIsShow().equals(1)).collect(Collectors.toList());
        for(int i=0;i<collect.size();i++){
            Date createTime = collect.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(localDate.isEqual(localDate1)){
                today++;
            }
            if(yesterday.isEqual(localDate1)){
                yesterday1++;
            }
            if(data1.isEqual(localDate1)){
                data1Num++;
            }
            if(data2.isEqual(localDate1)){
                data2Num++;
            }
            if(data3.isEqual(localDate1)){
                data3Num++;
            }
            if(data4.isEqual(localDate1)){
                data4Num++;
            }
            if(data5.isEqual(localDate1)){
                data5Num++;
            }
            if(data6.isEqual(localDate1)){
                data6Num++;
            }
            if(data7.isEqual(localDate1)){
                data7Num++;
            }
        }
        ArrayList<String> arrayList = new ArrayList<>();
        ArrayList<String> arrayList1 = new ArrayList<>();
        ArrayList<String> arrayList2 = new ArrayList<>();
        ArrayList<String> arrayList3 = new ArrayList<>();
        ArrayList<String> arrayList4 = new ArrayList<>();
        ArrayList<String> arrayList5 = new ArrayList<>();
        ArrayList<String> arrayList6 = new ArrayList<>();
        ArrayList<String> arrayList7 = new ArrayList<>();
        extracted(today, yesterday1, decline, add,arrayList);
        extracted(yesterday1, data1Num, decline, add,arrayList1);
        extracted(data1Num, data2Num, decline, add,arrayList2);
        extracted(data2Num, data3Num, decline, add,arrayList3);
        extracted(data3Num, data4Num, decline, add,arrayList4);
        extracted(data4Num, data5Num, decline, add,arrayList5);
        extracted(data5Num, data6Num, decline, add,arrayList6);
        extracted(data6Num, data7Num, decline, add,arrayList7);
        List<ArrayList<String>> list = Arrays.asList(arrayList, arrayList1,arrayList2,arrayList3,arrayList4,arrayList5,arrayList6,arrayList7);
        basicDataVO.setData(list);
        return basicDataVO;
    }

    private static void extracted(int today, int yesterday1, String decline, String add,ArrayList<String> arrayList) {
        String temp;
        if(today > yesterday1){
            double toNum= today;
            double yeNum= yesterday1;
            int rate= (int) (((toNum-yeNum)/toNum)*100);
            temp="<span  class='colorRed'>"+ decline +rate+"</span>";
        }else {
            double toNum= today;
            double yeNum= yesterday1;
            int rate= (int) (((yeNum-toNum)/yeNum)*100);
            temp="<span  class='colorGrass'>"+ add +rate+"</span>";
        }

        arrayList.add(String.valueOf(today));
        arrayList.add(String.valueOf(yesterday1));
        arrayList.add(temp);
    }

    public BasicDataVO customerNumber() {
        LocalDate localDate = LocalDate.now();
        LocalDate  data1  = localDate.minusDays(1);
        LocalDate  data2  = localDate.minusDays(2);
        LocalDate  data3  = localDate.minusDays(3);
        LocalDate  data4  = localDate.minusDays(4);
        LocalDate  data5  = localDate.minusDays(5);
        LocalDate  data6  = localDate.minusDays(6);
        LocalDate  data7  = localDate.minusDays(7);
        int number1,reNumber1=0;
        int number2,reNumber2=0;
        int number3,reNumber3=0;
        int number4,reNumber4=0;
        int number5,reNumber5=0;
        int number6,reNumber6=0;
        int number7,reNumber7=0;
        BasicDataVO basicDataVO = new BasicDataVO();
        ArrayList<Integer> integers = new ArrayList<>();
        ArrayList<Integer> repIntegers = new ArrayList<>();
        List<CustomerNumberDO> customerNumberDOS = customerNumberDAO.selectAll();
        for(int i=0;i<customerNumberDOS.size();i++){
            Date createTime = customerNumberDOS.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(data1.isEqual(localDate1)){
                number1=customerNumberDOS.get(i).getUserNumber();
                reNumber1=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number1);
                repIntegers.add(reNumber1);
            }
            if(data2.isEqual(localDate1)){
                number2=customerNumberDOS.get(i).getUserNumber();
                reNumber2=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number2);
                repIntegers.add(reNumber2);
            }
            if(data3.isEqual(localDate1)){
                number3=customerNumberDOS.get(i).getUserNumber();
                reNumber3=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number3);
                repIntegers.add(reNumber3);
            }
            if(data4.isEqual(localDate1)){
                number4=customerNumberDOS.get(i).getUserNumber();
                reNumber4=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number4);
                repIntegers.add(reNumber4);
            }
            if(data5.isEqual(localDate1)){
                number5=customerNumberDOS.get(i).getUserNumber();
                reNumber5=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number5);
                repIntegers.add(reNumber5);
            }
            if(data6.isEqual(localDate1)){
                number6=customerNumberDOS.get(i).getUserNumber();
                reNumber6=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number6);
                repIntegers.add(reNumber6);
            }
            if(data7.isEqual(localDate1)){
                number7=customerNumberDOS.get(i).getUserNumber();
                reNumber7=customerNumberDOS.get(i).getReplyNumber();
                integers.add(number7);
                repIntegers.add(reNumber7);
            }
        }
        DataVO9 dataVO9 = new DataVO9(integers, repIntegers);
        basicDataVO.setData(dataVO9);
        return  basicDataVO;

    }

    public BasicDataVO regionalReleases() {
        BasicDataVO basicDataVO = new BasicDataVO();
        ArrayList<String> category = new ArrayList<>();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectAll();
        List<EnterpriseCertificationDO> collect = enterpriseCertificationDOS.stream().filter(item -> item.getCertificationResults().equals(1)).collect(Collectors.toList());
        List<String> collect1 = collect.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        category.addAll(collect1);
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        List<String> collect2 = userAuthenticationDOS.stream().map(item -> item.getMapAddress()).collect(Collectors.toList());
        category.addAll(collect2);
        List<String> category1 = category.stream().distinct().collect(Collectors.toList());
        category1.removeAll(Collections.singleton(null));
        collect1.removeAll(Collections.singleton(null));
        Map<String, Integer> entMaps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect1)){
            for (String k: collect1) {
                Integer count = entMaps.get(k);
                entMaps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> entAddress = entMaps.keySet().stream().collect(Collectors.toList());
        List<Integer> entNumber = entMaps.values().stream().collect(Collectors.toList());
        collect2.removeAll(Collections.singleton(null));
        Map<String, Integer> userMaps = new HashMap<>();
        if(!CollectionUtils.isEmpty(collect2)){
            for (String k: collect2) {
                Integer count = userMaps.get(k);
                userMaps.put(k, (count == null) ? 1 : count + 1);
            }
        }
        List<String> userAddress = userMaps.keySet().stream().collect(Collectors.toList());
        List<Integer> userNumber = userMaps.values().stream().collect(Collectors.toList());
        List<Integer> barData = new ArrayList<>();
        List<Integer> lineData = new ArrayList<>();
        List<Integer> rateData = new ArrayList<>();
        for(int i=0;i<category1.size();i++){
            barData.add(0);
            lineData.add(0);
        }

        for(int i=0;i<category1.size();i++){
            int isValue=0;
            for(int j=0;j<entAddress.size();j++){
                if(isValue==0){
                    lineData.set(i,0);
                }else {
                    continue;
                }
                if(category1.get(i).equals(entAddress.get(j))){
                    lineData.set(i,entNumber.get(j));
                    isValue=1;
                }
            }
        }
        for(int i=0;i<category1.size();i++){
            int isValue=0;
            for(int j=0;j<userAddress.size();j++){
                if(isValue==0){
                    barData.set(i,0);
                }else {
                    continue;
                }
                if(category1.get(i).equals(userAddress.get(j))){
                    barData.set(i,userNumber.get(j));
                    isValue=1;
                }
            }
        }
        DataVO10 dataVO10 = new DataVO10(category1,lineData,barData,rateData);
        basicDataVO.setData(dataVO10);

        return  basicDataVO;

    }

    public BasicDataVO radar() {
        int falsh=0;
        List<CompetitionDO> competitionDOList = competitionDAO.selectAll();
        List<CompetitionDO> openly = competitionDOList.stream().filter(item -> item.getIsPublic() == 1).collect(Collectors.toList());
        List<CompetitionDO> nonPublic = competitionDOList.stream().filter(item -> item.getIsPublic() == 0).collect(Collectors.toList());
        BasicDataVO basicDataVO = new BasicDataVO();
        Calendar date = Calendar.getInstance();
        List<List<Integer>> radarData=new ArrayList<List<Integer>>();
        List<List<Integer>> radarDataAvg=new ArrayList<List<Integer>>();
        List<Integer> radar1 = new ArrayList<Integer>();
        List<Integer> radarAvg = new ArrayList<Integer>();
        if(CollectionUtils.isEmpty(openly)){
            radar1.add(0);
            radar1.add(0);
            radar1.add(0);
            radar1.add(0);
            radar1.add(0);
            radar1.add(0);
            radar1.add(0);
            falsh=1;
        }
        List<String> weekCategory = new ArrayList<>();
        String year = String.valueOf(date.get(Calendar.YEAR));
        LocalDate localDate = LocalDate.now();
        LocalDate  data1  = localDate.minusDays(1);
        LocalDate  data2  = localDate.minusDays(2);
        LocalDate  data3  = localDate.minusDays(3);
        LocalDate  data4  = localDate.minusDays(4);
        LocalDate  data5  = localDate.minusDays(5);
        LocalDate  data6  = localDate.minusDays(6);
        LocalDate  data7  = localDate.minusDays(7);
        int dataNum1=0;
        int dataNum2=0;
        int dataNum3=0;
        int dataNum4=0;
        int dataNum5=0;
        int dataNum6=0;
        int dataNum7=0;
        int nonDataNum1=0;
        int nonDataNum2=0;
        int nonDataNum3=0;
        int nonDataNum4=0;
        int nonDataNum5=0;
        int nonDataNum6=0;
        int nonDataNum7=0;



        DateTimeFormatter df = DateTimeFormatter.ofPattern("MM/dd");
        weekCategory.add(data7.format(df));
        weekCategory.add(data6.format(df));
        weekCategory.add(data5.format(df));
        weekCategory.add(data4.format(df));
        weekCategory.add(data3.format(df));
        weekCategory.add(data2.format(df));
        weekCategory.add(data1.format(df));
        for(int i=0;i<openly.size();i++){
            Date createTime = openly.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(data1.isEqual(localDate1)){
                dataNum1++;
            }
            if(data2.isEqual(localDate1)){
                dataNum2++;
            }
            if(data3.isEqual(localDate1)){
                dataNum3++;
            }
            if(data4.isEqual(localDate1)){
                dataNum4++;
            }
            if(data5.isEqual(localDate1)){
                dataNum5++;
            }
            if(data6.isEqual(localDate1)){
                dataNum6++;
            }
            if(data7.isEqual(localDate1)){
                dataNum7++;
            }
        }
        if(falsh==0){
            radar1.add(dataNum1);
            radar1.add(dataNum2);
            radar1.add(dataNum3);
            radar1.add(dataNum4);
            radar1.add(dataNum5);
            radar1.add(dataNum6);
            radar1.add(dataNum7);
        }
        radarData.add(radar1);
        for(int i=0;i<nonPublic.size();i++){
            Date createTime = nonPublic.get(i).getCreateTime();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(data1.isEqual(localDate1)){
                nonDataNum1++;
            }
            if(data2.isEqual(localDate1)){
                nonDataNum2++;
            }
            if(data3.isEqual(localDate1)){
                nonDataNum3++;
            }
            if(data4.isEqual(localDate1)){
                nonDataNum4++;
            }
            if(data5.isEqual(localDate1)){
                nonDataNum5++;
            }
            if(data6.isEqual(localDate1)){
                nonDataNum6++;
            }
            if(data7.isEqual(localDate1)){
                nonDataNum7++;
            }
        }
        radarAvg.add(nonDataNum1);
        radarAvg.add(nonDataNum2);
        radarAvg.add(nonDataNum3);
        radarAvg.add(nonDataNum4);
        radarAvg.add(nonDataNum5);
        radarAvg.add(nonDataNum6);
        radarAvg.add(nonDataNum7);
        radarDataAvg.add(radarAvg);
        int max;
        int maxByFor1 = findMaxByFor(radar1);
        int maxByFor2 = findMaxByFor(radarAvg);
        max = Math.max(maxByFor1, maxByFor2);
        ArrayList<Integer> weekMaxData = new ArrayList<>();
        for(int i=0;i<7;i++){
            weekMaxData.add(max);
        }
        ArrayList<Integer> weekLineData = new ArrayList<>();
        weekLineData.addAll(radar1);
        weekLineData.add(max);
        DataVO11 dataVO11 = new DataVO11(Integer.valueOf(year),weekCategory,radarData,radarDataAvg,max,weekMaxData,weekLineData);
        basicDataVO.setData(dataVO11);
        return basicDataVO;
    }
    private static int findMaxByFor(List<Integer> arr) {
        int max = 0; // 最大值
        for (int item : arr) {
            if (item > max) { // 当前值大于最大值，赋值为最大值
                max = item;
            }
        }
        return max;
    }

    public Result uploadDocument(StageFormDTO stageFormDTO) {
        UserDO userDO = userDAO.selectByUsername(stageFormDTO.getUsername());
        StageFormDO stageFormDO = new StageFormDO();
        stageFormDO.setEntName(userDO.getEntName());
        stageFormDO.setPersonalName(userDO.getIndividual());
        BeanUtils.copyProperties(stageFormDTO,stageFormDO);
        List<String> advancedAchievements = new ArrayList<>();
        List<String> advancedDemands = new ArrayList<>();
        if (stageFormDTO.getAdvancedAchievements() != null) {
            for (int i = 0; i < stageFormDTO.getAdvancedAchievements().size(); i++) {
                String image = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(stageFormDTO.getAdvancedAchievements())) {
                    String imagePath = FileUtils.saveMultipartFile2(stageFormDTO.getAdvancedAchievements().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + image,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
                    advancedAchievements.add(imagePath);
                }
                stageFormDO.setAdvancedAchievements(advancedAchievements);
            }
        }
        if (stageFormDTO.getAdvancedDemand() != null) {
            for (int i = 0; i < stageFormDTO.getAdvancedDemand().size(); i++) {
                String image = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(stageFormDTO.getAdvancedDemand())) {
                    String imagePath = FileUtils.saveMultipartFile2(stageFormDTO.getAdvancedDemand().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + image,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
                    advancedDemands.add(imagePath);
                }
                stageFormDO.setAdvancedDemand(advancedDemands);
            }
        }

        stageFormDAO.insert(stageFormDO);

        return  Result.success("收集完成");
    }

    public BasicDataVO userSign() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<SingInRecordDO> singInRecordDOS = singInRecordDAO.selectAll();
        List<SingInRecordDO> collect = singInRecordDOS.stream().filter(item -> item.getIsSign().equals(1)).collect(Collectors.toList());
        LocalDate localDate =LocalDate.now();
        LocalDate MONDAY;
        MONDAY = localDate.minusDays(1);
        LocalDate TUESDAY;
        TUESDAY = localDate.minusDays(2);
        LocalDate WEDNESDAY;
        WEDNESDAY = localDate.minusDays(3);
        LocalDate THURSDAY;
        THURSDAY = localDate.minusDays(4);
        LocalDate FRIDAY;
        FRIDAY = localDate.minusDays(5);
        LocalDate SATURDAY;
        SATURDAY = localDate.minusDays(6);
        LocalDate SUNDAY;
        SUNDAY = localDate.minusDays(7);
        int signData=0,signData1=0,signData2=0,signData3=0,signData4=0,signData5=0,signData6=0;
        for(int i=0;i<collect.size();i++){
            Date createTime = collect.get(i).getSignDate();
            LocalDate localDate1= createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            if(SUNDAY.isEqual(localDate1)){
                signData++;
            }
            if(SATURDAY.isEqual(localDate1)){
                signData1++;
            }
            if(FRIDAY.isEqual(localDate1)){
                signData2++;
            }
            if(THURSDAY.isEqual(localDate1)){
                signData3++;
            }
            if(WEDNESDAY.isEqual(localDate1)){
                signData4++;
            }
            if(TUESDAY.isEqual(localDate1)){
                signData5++;
            }
            if(MONDAY.isEqual(localDate1)){
                signData6++;
            }

        }
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM,dd");
        List<Integer> data1 = Arrays.asList(signData, signData1, signData2, signData3, signData4, signData5, signData6);
        List<String> data2 = Arrays.asList(dtf.format(SUNDAY), dtf.format(SATURDAY), dtf.format(FRIDAY),dtf.format(THURSDAY), dtf.format(WEDNESDAY), dtf.format(TUESDAY), dtf.format(MONDAY));
        DataVO13 dataVO13 = new DataVO13(data1, data2);
        basicDataVO.setData(dataVO13);
        return   basicDataVO;
    }
    public String phoneSecrecy(String phoneNum){
        if(phoneNum != null && phoneNum.length() > 4){
            if(phoneNum.length() == 11){
                phoneNum = phoneNum.substring(0, 3) + "****" + phoneNum.substring(7, phoneNum.length());
            }else{
                phoneNum = phoneNum.substring(0,phoneNum.length()-1) + "*";
            }
        }
        return phoneNum;
    }

    public BasicDataVO pointSort() {
        BasicDataVO basicDataVO = new BasicDataVO();
        List<List<String>> lists = new ArrayList<>();
        List<UserDO> userDOS = userDAO.selectBySortPoint();
        for(int i=0;i<userDOS.size();i++){
            ArrayList<String> arrayList = new ArrayList<>();
            arrayList.add(phoneSecrecy(userDOS.get(i).getUsername()));
            arrayList.add(String.valueOf(userDOS.get(i).getPoints()));
            lists.add(arrayList);
        }
        basicDataVO.setData(lists);
        return  basicDataVO;
    }

    public Result showTable(HttpServletRequest request) {
        String username = JwtUtils.getUsername(request);
        List<UserFormsDO> userFormsDOS = userFormsDAO.selectByUserName(username);
        return  Result.success(userFormsDOS);

    }

    public Result showUserList(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String username = MapUtils.getString(params, "username");
        String state = MapUtils.getString(params, "state");
        //根据浏览量排序
        String startTime = MapUtils.getString(params, "startTime");
        String endTime = MapUtils.getString(params, "endTime");
        if(username.equals("")&&state.equals("")&&startTime.equals("")&&endTime.equals("")){
            Page<UserDO> userList=  userDAO.getUserListByPage(new Page<>(pagination.getPageNum(), pagination.getSize()));
            return Result.success(userList);
        }
        else if(startTime.equals("")&&endTime.equals("")){
            Page<UserDO> userList=  userDAO.getByPageUserNameAndState(new Page<>(pagination.getPageNum(), pagination.getSize()),username,state);
            return Result.success(userList);
        }
        else if(username.equals("")&&state.equals("")){
            Page<UserDO> userList = userDAO.getUserListByTime(new Page<>(pagination.getPageNum(), pagination.getSize()),startTime,endTime);
            return  Result.success(userList);
        }else if(username.equals("")&&!state.equals("")){
            Page<UserDO> userList = userDAO.getUserListByState(new Page<>(pagination.getPageNum(), pagination.getSize()),state,startTime,endTime);
            return  Result.success(userList);
        }else {
            Page<UserDO> userList = userDAO.getUserList(new Page<>(pagination.getPageNum(), pagination.getSize()),username,state,startTime,endTime);
            return  Result.success(userList);
        }
    }

    public Result editUserList(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userDTO,userDO);
        userDAO.updateById(userDO);
        return  Result.success("修改用户信息成功");
    }

    public Result resetPassword(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userDTO,userDO);
        String password = DigestUtil.sha256Hex(userDTO.getPassword());
        userDO.setPassword(password);
        userDAO.updateById(userDO);
        return  Result.success("重置密码成功");
    }

    public Result onlineUser(PageRequest pageRequest) {
        Page<UsersOnlineDO> usersOnlineDOPage;
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String address = MapUtils.getString(params, "address");
        String username = MapUtils.getString(params, "username");
        if(address.equals("")&&username.equals("")){
             usersOnlineDOPage= usersOnlineDAO.selectByPage(pagination);
            return  Result.success(usersOnlineDOPage);
        }
        else if(username.equals("")&&!address.equals("")){
            usersOnlineDOPage= usersOnlineDAO.selectByPageAddress(pagination,address);
            return  Result.success(usersOnlineDOPage);
        }
        else{
           usersOnlineDOPage = usersOnlineDAO.getOnlineUser(new Page<UsersOnlineDO>(pagination.getPageNum(), pagination.getSize()),username,address);
            return  Result.success(usersOnlineDOPage);
        }

    }

    public Result addUser(UserDTO userDTO) {
        return  null;
    }

    public Result updateUserState(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userDTO,userDO);
        userDAO.updateById(userDO);
        return  Result.success("修改用户状态成功");
    }

    public Result assignPermissions(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        BeanUtils.copyProperties(userDTO,userDO);
        userDAO.updateById(userDO);
        return  Result.success("修改用户权限成功");
    }

    public Result userRegistration() {
        ArrayList<String> arrayList = new ArrayList<>();
        List<UserDO> userDOS = userDAO.selectAll();
        List<UserDO> collect = userDOS.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        arrayList.add(String.valueOf(collect.size()));
        int thisMonth = 0;
        int lastMonth = 0;
        double add1;
        double add2;
        double result;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
        Date date = new Date(System.currentTimeMillis());

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        for (int i = 0; i < collect.size(); i++) {
            Date createTime = collect.get(i).getCreateTime();
            String format = formatter.format(createTime);
            if (format.equals(formatter.format(date))) {
                thisMonth++;
            }
        }
        arrayList.add("增加");
        add1 = thisMonth;
        add2 = collect.size();
        result=(add1/add2)*100;
        BigDecimal bd = new BigDecimal(result);
        double v = bd.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        arrayList.add(String.valueOf(v));
        return Result.success(arrayList);
    }

    public Result entRealName() {
        ArrayList<String> arrayList = new ArrayList<>();
        List<EnterpriseCertificationDO> enterpriseCertificationDOS = enterpriseCertificationDAO.selectHave();
        arrayList.add(String.valueOf(enterpriseCertificationDOS.size()));
        int thisMonth=0;
        double add1;
        double add2;
        double result;
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM");
        Date date = new Date(System.currentTimeMillis());

        Calendar calendar = Calendar.getInstance();
        // 设置为当前时间
        calendar.setTime(date);
        // 设置为上一个月
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
        Date time = calendar.getTime();
        String format2 = formatter.format(time);
        System.out.println(format2);

        for(int i=0;i<enterpriseCertificationDOS.size();i++){
            Date createTime = enterpriseCertificationDOS.get(i).getCreateTime();
            String format = formatter.format(createTime);
            if(format.equals(formatter.format(date))){
                thisMonth++;
            }
        }

        arrayList.add("增加");
        add1 = thisMonth;
        add2 = enterpriseCertificationDOS.size();
        result=(add1/add2)*100;
        BigDecimal bd = new BigDecimal(result);
        double v = bd.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        arrayList.add(String.valueOf(v));
        return  Result.success(arrayList);
    }

    public Result questionsRegistration2() {
        ArrayList<String> arrayList = new ArrayList<>();
        List<ApplicationV2DO> applicationV2DOS = applicationV2DAO.selectAll();
        arrayList.add(String.valueOf(applicationV2DOS.size()));
        int thisMonth=0;
        int lastMonth=0;
        double add1;
        double add2;
        double result;
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM");
        Date date = new Date(System.currentTimeMillis());

        Calendar calendar = Calendar.getInstance();
        // 设置为当前时间
        calendar.setTime(date);
        // 设置为上一个月
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
        Date time = calendar.getTime();
        String format2 = formatter.format(time);
        System.out.println(format2);

        for(int i=0;i<applicationV2DOS.size();i++){
            Date createTime = applicationV2DOS.get(i).getCreateTime();
            String format = formatter.format(createTime);
            if(format.equals(formatter.format(date))){
                thisMonth++;
            }
        }
        arrayList.add("增加");
        add1 = thisMonth;
        add2 = applicationV2DOS.size();
        result=(add1/add2)*100;
        BigDecimal bd = new BigDecimal(result);
        double v = bd.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        arrayList.add(String.valueOf(v));
        return  Result.success(arrayList);
    }

    public Result showProducts2() {
        ArrayList<String> arrayList = new ArrayList<>();
        List<DemandDO> demandDOS = demandDAO.selectAllByIsShow();
        arrayList.add(String.valueOf(demandDOS.size()));
        int thisMonth=0;
        double add1;
        double add2;
        double result;
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM");
        Date date = new Date(System.currentTimeMillis());

        Calendar calendar = Calendar.getInstance();
        // 设置为当前时间
        calendar.setTime(date);
        // 设置为上一个月
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
        Date time = calendar.getTime();
        String format2 = formatter.format(time);
        System.out.println(format2);

        for(int i=0;i<demandDOS.size();i++){
            Date createTime = demandDOS.get(i).getCreateTime();
            String format = formatter.format(createTime);
            if(format.equals(formatter.format(date))){
                thisMonth++;
            }

        }
        arrayList.add("增加");
        add1 = thisMonth;
        add2 = demandDOS.size();
        result=(add1/add2)*100;
        BigDecimal bd = new BigDecimal(result);
        double v = bd.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
        arrayList.add(String.valueOf(v));
        return  Result.success(arrayList);
    }
    public Result pointSort2() {
        List<UserDO> userDOS = userDAO.selectBySort();
        List<UserDO> collect = userDOS.stream().filter(item -> !item.getUsername().equals("admin")).collect(Collectors.toList());
        return  Result.success(collect);
    }

    public Result showTableData() {
        ArrayList<Integer> integers = new ArrayList<>();
        List<UserFormsDO> userFormsDOS = userFormsDAO.selectAll();
        List<UserFormsDO> userFormsDOS1 = userFormsDAO.selectByHavaWirte();
        integers.add(userFormsDOS.size());
        integers.add(userFormsDOS1.size());
        integers.add(userFormsDOS.size()-userFormsDOS1.size());
        return  Result.success(integers);
    }

    public Result otherShow() {
        List<MeetingDO> meetingDOS = meetingDAO.selectAll();
        List<UserAuthenticationDO> userAuthenticationDOS = userAuthenticationDAO.selectAll();
        List<AgencyProductRelationshipsDO> agencyProductRelationshipsDOS = agencyProductRelationshipsDAO.selectByHavaAgecy();
        List<WebViewDO> webViewDOS = webViewDAO.selectAll();
        List<ExpertInfoDO> expertInfoDOS = expertInfoDAO.selectAll();
        List<Integer> list = Arrays.asList(userAuthenticationDOS.size(),meetingDOS.size(),
                agencyProductRelationshipsDOS.size(),webViewDOS.get(0).getWebsiteViews(),expertInfoDOS.size());
        return  Result.success(list);
    }

    public Result forcedOffline(UserDTO userDTO) {
        String username = userDTO.getUsername();
        redisUtils.set(username,"");
        return Result.success("强制下线成功");
    }

    public Result listProducts2(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String name = MapUtils.getString(params, "name");
        String status = MapUtils.getString(params, "status");
        String startTime = MapUtils.getString(params, "startTime");
        String endTime = MapUtils.getString(params, "endTime");
        if(name.equals("")&&startTime.equals("")&&endTime.equals("")&&status.equals("")){
            IPage<DemandDO> demandDOS = demandDAO.selectByAllPage(pagination);
            return Result.success(demandDOS);
        }
        else if(startTime.equals("")&&endTime.equals("")){
            if(name.equals("")){
                IPage<DemandDO> demandDOS = demandDAO.selectByPageStatus(new Page<DemandDO>(pagination.getPageNum(), pagination.getSize()),status);
                return  Result.success(demandDOS);
            }else {
                IPage<DemandDO> demandDOS = demandDAO.selectByPageAndLikeNameStatus(new Page<DemandDO>(pagination.getPageNum(), pagination.getSize()), name,status);
                return  Result.success(demandDOS);
            }
        }
        else if(name.equals("")&&!startTime.equals("")&&!endTime.equals("")&&status.equals("")){
            IPage<DemandDO> demandDOS = demandDAO.selectByPageAndTime(new Page<DemandDO>(pagination.getPageNum(), pagination.getSize()),  startTime, endTime);
            return Result.success(demandDOS);
        }else if(name.equals("")&&!startTime.equals("")&&!endTime.equals("")&&!status.equals("")) {
            IPage<DemandDO> demandDOS = demandDAO.selectByPageStatusAndTime(new Page<DemandDO>(pagination.getPageNum(), pagination.getSize()), startTime, endTime,status);
            return Result.success(demandDOS);
        }
        else {
            IPage<DemandDO> demandDOS = demandDAO.selectByPageAndAll(new Page<DemandDO>(pagination.getPageNum(), pagination.getSize()),name,status, startTime, endTime);
            return Result.success(demandDOS);
        }
    }
    public Result showUserOperate(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String type = MapUtils.getString(params, "type");
        if(type.equals("")){
            IPage<BmsLog> bmsLogIPage = bmsLogServiceDAO.selectByPage(new Page<>(pagination.getPageNum(), pagination.getSize()));
            return  Result.success(bmsLogIPage);
        }
        IPage<BmsLog> bmsLogIPage = bmsLogServiceDAO.selectByPageAndType(new Page<>(pagination.getPageNum(), pagination.getSize()),type);
        return  Result.success(bmsLogIPage);
    }

    public Result personalName(PageRequest pageRequest) {
        IPage<PersonVO> userAuthenticationDOIPage;
        ArrayList<PersonVO> personVOS = new ArrayList<>();
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String name = MapUtils.getString(params, "name");
        if(name.equals("")){
            userAuthenticationDOIPage= userAuthenticationDAO.selectByOtherType(new Page<>(pagination.getPageNum(),pagination.getSize()));
        }else {
            userAuthenticationDOIPage= userAuthenticationDAO.selectByOtherName(new Page<>(pagination.getPageNum(),pagination.getSize()),name);
        }

        List<UserDO> userDOS = userDAO.selectAll();
        List<PersonVO> records = userAuthenticationDOIPage.getRecords();
        List<UserDO> collect = userDOS.stream().filter(item -> item.getIsAuthentication().equals(1)).collect(Collectors.toList());
        for(int i=0;i<records.size();i++){
            PersonVO personVO = new PersonVO();
            for(int j=0;j<collect.size();j++){
                if(records.get(i).getPhone().equals(collect.get(j).getUsername())){
                    BeanUtils.copyProperties(records.get(i),personVO);
                    personVO.setAvatar(collect.get(j).getAvatar());
                    personVO.setIndustry(collect.get(j).getIndustry());
                    personVO.setEmail(collect.get(j).getEmail());
                    personVOS.add(personVO);
                }
            }
        }
        userAuthenticationDOIPage.setRecords(personVOS);
        return  Result.success(userAuthenticationDOIPage);
    }

    public Result entAuthentication(PageRequest pageRequest) {
        IPage<EnterpriseCertificationDO> enterpriseCertificationDOIPage;
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String name = MapUtils.getString(params, "name");
        String state = MapUtils.getString(params, "state");
        if(!name.equals("")&&!state.equals("")){
             enterpriseCertificationDOIPage = enterpriseCertificationDAO.selectByPageByEntNameAndState(pagination, name,state);
            return  Result.success(enterpriseCertificationDOIPage);
        }else  if(!name.equals("")&&state.equals("")){
            enterpriseCertificationDOIPage = enterpriseCertificationDAO.selectByPageByEntName(pagination, name);
            return  Result.success(enterpriseCertificationDOIPage);
        }else if(name.equals("")&&!state.equals("")){
            enterpriseCertificationDOIPage=enterpriseCertificationDAO.selectByState(pagination,state);
            return  Result.success(enterpriseCertificationDOIPage);
        }
           else {
            enterpriseCertificationDOIPage=enterpriseCertificationDAO.selectByPage(pagination);
            return  Result.success(enterpriseCertificationDOIPage);
        }
     }

    public Result newBulletin(PageRequest pageRequest) {
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String name = MapUtils.getString(params, "name");
        IPage<NewsDO> newsDOIPage = newsDAO.selectByPage(new Page<NewsDO>(pagination.getPageNum(), pagination.getSize()),name);
        return  Result.success(newsDOIPage);
    }

    public Result addBulletin(NewsDTO newsDTO) {
        NewsDO newsDO = new NewsDO();
        BeanUtils.copyProperties(newsDTO,newsDO);
        newsDAO.insert(newsDO);
        return  Result.success("新增新闻公告成功");
    }

    public Result updateNewBulletin(NewsDTO newsDTO) {
        NewsDO newsDO = newsDAO.selectById(newsDTO.getId());
        BeanUtils.copyProperties(newsDTO,newsDO);
        newsDAO.updateById(newsDO);
        return  Result.success("修改新闻公告成功");
    }

    public Result deleteNewBulletin(String id) {
        newsDAO.deleteById(Integer.parseInt(id));
        return  Result.success("删除新闻公告成功");
    }

    public Result entDetail2(String name) {
        String key="entDetail:"+name;
        String redisData = redisUtils.get(key);
        if(StringUtils.isNotEmpty(redisData)){
            return  Result.success(redisData);
        }else {
            String apiKey = "6b0ab7e14ed9952473f58394d9b00a84";
            String apiUrl = "http://japi.juhe.cn/enterprise/simpleList";
            String result = sendGetRequestWithParameters(apiUrl, "key", apiKey, "keyword", name);
            List<EntRelationsDO> entRelationsDOS = entRelationsDAO.selectByName(name);
            if(!CollectionUtils.isEmpty(entRelationsDOS)){
                return  Result.success(entRelationsDOS.get(0).getEntData());
            }
            redisUtils.set(key,result);
            EntRelationsDO entRelationsDO = new EntRelationsDO();
            entRelationsDO.setEntName(name);
            entRelationsDO.setEntData(result);
            entRelationsDAO.insert(entRelationsDO);
            return  Result.success(result);
        }
    }

    public static String sendGetRequestWithParameters(String baseUrl, String parameterName, String parameterValue, String parameterName2, String parameterValue2) {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            String urlWithParameters = buildUrlWithMultipleParameters(baseUrl, parameterName, parameterValue,parameterName2,parameterValue2);
            HttpGet httpGet = new HttpGet(urlWithParameters);

            CloseableHttpResponse response = httpClient.execute(httpGet);

            int statusCode = response.getStatusLine().getStatusCode();

            if (statusCode == 200) {
                HttpEntity entity = response.getEntity();
                String responseBody = EntityUtils.toString(entity);
                return  responseBody;
            } else {
                return  "Request failed with status code:" + statusCode;
            }

        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
        return  null;
    }
    public static String buildUrlWithMultipleParameters(String baseUrl, String parameter1Name, String parameter1Value, String parameter2Name, String parameter2Value) throws URISyntaxException {
        URI uri = new URI(baseUrl);
        StringBuilder queryBuilder = new StringBuilder();
        queryBuilder.append(parameter1Name).append("=").append(parameter1Value);
        queryBuilder.append("&").append(parameter2Name).append("=").append(parameter2Value);
        URI uriWithParameters = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), queryBuilder.toString(), uri.getFragment());
        return uriWithParameters.toString();
    }

    public Result submission(PageRequest pageRequest) {
        IPage<CompetitionSubmissionVO> competitionSubmissionVOIPage=null;
        Pagination pagination = pageRequest.getPagination();
        Map<String, Object> params = pageRequest.getParams();
        String name = MapUtils.getString(params, "name");
        String state = MapUtils.getString(params, "state");
        Page<CompetitionSubmissionVO> competitionSubmissionVOPage = new Page<>(pagination.getPageNum(), pagination.getSize());
         competitionSubmissionVOIPage = competitionSubmissionDAO.selectByPageNameAndState(competitionSubmissionVOPage, name, state);
        List<CompetitionSubmissionVO> records = competitionSubmissionVOIPage.getRecords();
        ArrayList<CompetitionSubmissionVO> competitionSubmissionVOS = new ArrayList<>();
        for(int i=0;i<records.size();i++){
            CompetitionSubmissionVO competitionSubmissionVO = new CompetitionSubmissionVO();
            BeanUtils.copyProperties(records.get(i),competitionSubmissionVO);
            List<ApplicationV2DO> applicationV2DOList = applicationV2DAO.selectHave(records.get(i).getUsername(), records.get(i).getCompetitionId());
            CompetitionParentDO competitionParentDO = competitionParentDAO.selectById(applicationV2DOList.get(0).getCompetitionParentId());
            competitionSubmissionVO.setPhone(applicationV2DOList.get(0).getPhone());
            competitionSubmissionVO.setContact(applicationV2DOList.get(0).getContact());
            competitionSubmissionVO.setCompetitionName(competitionParentDO.getTitle());
            competitionSubmissionVO.setEntName(applicationV2DOList.get(0).getBizName());
            competitionSubmissionVO.setQuestionsName(applicationV2DOList.get(0).getCompetitionName());
            competitionSubmissionVOS.add(competitionSubmissionVO);
        }
        competitionSubmissionVOIPage.setRecords(competitionSubmissionVOS);
        return  Result.success(competitionSubmissionVOIPage);
    }

    public Result showProductHistory(Integer  productId) {
        List<DemandRecordDO> demandRecordDOS = demandRecordDAO.selectByProductId(productId);
        return  Result.success(demandRecordDOS);
    }

    public Result entData(PageRequest pageRequest) {
        Map<String, Object> params = pageRequest.getParams();
        Pagination pagination = pageRequest.getPagination();
        String name = MapUtils.getString(params, "name");
        IPage<EnterpriseDataDO> enterpriseDataDOIPage = enterpriseDataDAO.selectByPageByEntNameAndName(pagination, name);
        return  Result.success(enterpriseDataDOIPage);
    }

    public Result adminUpdateProducts(DemandDTO demandDTO) {
        AgencyProductRelationshipsDO agencyProductRelationshipsDO = agencyProductRelationshipsDAO.selectByProductId(demandDTO.getId());
        ArrayList<String> imagePaths = new ArrayList<>();
        ArrayList<String> outcomeInformation = new ArrayList<>();
        ArrayList<String> attachments = new ArrayList<>();
        DemandDO demandDO = new DemandDO();
        BeanUtils.copyProperties(demandDTO, demandDO);
        DemandRecordDO demandRecordDO = new DemandRecordDO();
        demandRecordDO.setProductId(demandDTO.getId());
        demandRecordDO.setUsername(demandDTO.getReviewer());
        demandRecordDO.setOperate("审核产品");
        demandRecordDAO.insert(demandRecordDO);
        if (demandDTO.getAttachment() != null) {
            for (int i = 0; i < demandDTO.getAttachment().size(); i++) {
                String attachment = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getAttachment())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getAttachment().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + attachment,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + attachment);
                    attachments.add(imagePath);
                }
                demandDO.setAttachment(attachments);
            }
        }

        if (demandDTO.getPicture() != null) {
            for (int i = 0; i < demandDTO.getPicture().size(); i++) {
                String image = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getPicture())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getPicture().get(i), devHttpPrefix+ DEMAND_PICTURE_PATH_PREFIX + image,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + image);
                    imagePaths.add(imagePath);
                }
            }
            demandDO.setPicture(imagePaths);

        }

        if (demandDTO.getOutcomeInformation() != null) {
            for (int i = 0; i < demandDTO.getOutcomeInformation().size(); i++) {
                String fileName = ValidateCodeUtils.generateCode(4);
                if (!ObjectUtils.isEmpty(demandDTO.getOutcomeInformation())) {
                    String imagePath = FileUtils.saveMultipartFile2(demandDTO.getOutcomeInformation().get(i), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + fileName,
                            FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + fileName);
                    outcomeInformation.add(imagePath);
                }
            }
            demandDO.setOutcomeInformation(outcomeInformation);

        }
        String videsName = ValidateCodeUtils.generateCode(4);
        if (!ObjectUtils.isEmpty(demandDTO.getProductVideos())) {
            String imagePath = FileUtils.saveMultipartFile2(demandDTO.getProductVideos(), devHttpPrefix + DEMAND_PICTURE_PATH_PREFIX + videsName,
                    FileUtils.staticPath + DEMAND_PICTURE_PATH_PREFIX + videsName);
            demandDO.setProductVideos(imagePath);
        }
        boolean b = demandDAO.updateById(demandDO);
        personalRecommendationsDAO.deleteByUsernameAndId(demandDTO.getUsername(),demandDTO.getId());
        if(demandDTO.getIsShow()!=null){
            if(demandDTO.getIsShow()==1){
                if(agencyProductRelationshipsDO!=null){
                    agencyProductRelationshipsDO.setProductState("已上架");
                    agencyProductRelationshipsDAO.updateById(agencyProductRelationshipsDO);
                }
                MessageDO messageDO = new MessageDO();
                messageDO.setType(1);
                messageDO.setTitle("上架产品消息");
                messageDO.setContent("您好!您的" + demandDTO.getDemandName() + "产品上架审核通过!");
                messageDO.setUsername(demandDTO.getUsername());
                messageDAO.insert(messageDO);
                TaskTagDO taskTagDO=taskTagDAO.selectByProductTaskName();
                TaskFinishDO taskFinishDO =taskFinishDAO.selecByTaskAndUser(taskTagDO.getId(),demandDTO.getUsername());
                if(taskFinishDO!=null){
                    //没有上架过产品才会加积分
                    PointBreakdownDO pointBreakdownDO = new PointBreakdownDO();
                    pointBreakdownDO.setType(productType);
                    pointBreakdownDO.setUsername(demandDTO.getUsername());
                    pointBreakdownDO.setDetails("上架产品"+demandDTO.getDemandName()+",获得"+productPoint+"积分");
                    pointBreakdownDO.setPoint("+"+productPoint);
                    UserDO userDO = userDAO.selectByUsername(demandDTO.getUsername());
                    userDO.setPoints(userDO.getPoints()+productPoint);
                    userDAO.updateById(userDO);
                    taskFinishDO.setIsFinish(1);
                    pointBreakdownDAO.insert(pointBreakdownDO);
                    taskFinishDAO.updateById(taskFinishDO);
                }
                try {
                    MessageUtils.sendMessage(demandDTO.getUsername(), sendMessageConfig.getSuccessProducts());
                }catch (Exception e){
                    SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                    smsErrLogDO.setPhone(demandDTO.getUsername());
                    smsErrLogDO.setType("上架产品审核通过");
                    smsErrLogDAO.insert(smsErrLogDO);
                }
            }
            if(demandDTO.getIsShow()==-1){
                if(agencyProductRelationshipsDO!=null){
                    agencyProductRelationshipsDO.setRemark(demandDTO.getFeedback());
                    agencyProductRelationshipsDO.setProductState("上架失败");
                    agencyProductRelationshipsDAO.updateById(agencyProductRelationshipsDO);
                }
                MessageDO messageDO = new MessageDO();
                messageDO.setType(1);
                messageDO.setTitle("上架产品消息");
                messageDO.setContent("您好!您的" + demandDTO.getDemandName() + "产品上架审核失败,请修改产品信息重试!失败原因为:"+demandDTO.getFeedback());
                messageDO.setUsername(demandDTO.getUsername());
                messageDAO.insert(messageDO);
                try{
                    MessageUtils.sendMessage(demandDTO.getUsername(),sendMessageConfig.getFailProducts());
                }catch(Exception e){
                    SmsErrLogDO smsErrLogDO = new SmsErrLogDO();
                    smsErrLogDO.setPhone(demandDTO.getUsername());
                    smsErrLogDO.setType("上架产品审核失败");
                    smsErrLogDAO.insert(smsErrLogDO);
                }

            }
        }
        if (b) {
            return Result.success(ResultCodeEnum.SUCCESS_UPDATE_Products);
        }
        return Result.success(ResultCodeEnum.Fail_UPDATE_Products);
    }
}
